Создание приложения для firestick, но кнопки не работают при нажатии и наведении

Я делаю приложение для 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);
                }
            }
        });
    }

person Arjun saini    schedule 27.01.2021    source источник


Ответы (1)


в 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>
person Arjun saini    schedule 06.02.2021