java - 为火棒制作应用程序,但按钮单击和悬停不起作用
问题描述
我正在为 firestick 制作应用程序,但没有点击或导航抽屉无法使用 Firestick Remote。
public class MainActivity extends AppCompatActivity {
int currentApiVersion;
SharedPreferences sharedpreferences;
String code = "";
public static DrawerLayout drawer_layout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
currentApiVersion = Build.VERSION.SDK_INT;
HideHomeButton.hidebar2(this);
setContentView(R.layout.activity_new_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this,android.R.color.black));
}
TextView menu_code = findViewById(R.id.menu_code);
drawer_layout = findViewById(R.id.drawer_layout);
sharedpreferences = this.getSharedPreferences("code_prefrances", Context.MODE_PRIVATE);
code = sharedpreferences.getString("code", "");
menu_code.setText(code);
HomeFragment fragment = new HomeFragment();
FragmentManager manager = getSupportFragmentManager();;
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container, fragment).addToBackStack(null);
transaction.commit();
findViewById(R.id.reset_code).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),CodeInputActvity.class);
startActivity(intent);
if (drawer_layout.isDrawerOpen(GravityCompat.END)) {
drawer_layout.closeDrawer(GravityCompat.END);
}
}
});
findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
if (drawer_layout.isDrawerOpen(GravityCompat.END)) {
drawer_layout.closeDrawer(GravityCompat.END);
}
}
});
findViewById(R.id.reboot_app).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences sharedpreferences = getSharedPreferences("code_prefrances", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.remove("code");
editor.commit();
Intent intent = new Intent(getApplicationContext(),SplashActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
if (drawer_layout.isDrawerOpen(GravityCompat.END)) {
drawer_layout.closeDrawer(GravityCompat.END);
}
}
});
}
解决方案
在 XML 中为我工作
<requestFocus/>
为了获得焦点,您需要像这样的背景选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_text_hover" android:state_pressed="true"></item>
<item android:drawable="@drawable/button_text_hover" android:state_activated="true"></item>
<item android:drawable="@drawable/button_text_hover" android:state_focused="true"></item>
<item android:drawable="@drawable/button_text_normal" ></item>
</selector>
推荐阅读
- c++ - 为什么 C++ 不读取我的 if-else 语句的下一行,尽管前面的语句不应该是真的?
- python - 有没有办法让 Pandas to_sql 函数变得冗长?
- java - IBM Websphere 中的 Java VisualVM JMX 连接
- java - 有没有一种简单的方法可以将 A 类的对象解析为 B 类的对象,该字段是 A 的子集?
- javascript - 与 HTML 和 Javascript 相关的数组问题
- javascript - 将任何 Nodejs 请求转发到其他服务器
- python - Pandas - groupby 索引作为列
- jquery - 根据其在 div 中的位置删除一项 (jQuery)
- node.js - 尝试调试需要 babel/register 的 nodejs 应用程序时连接被拒绝
- android - Firebase 应用程序分发与 gradle,同时具有多个 flavorDimensions