And*_*ich 6 android android-support-library android-actionbar-compat
我正在我的应用程序中实现一些控制器/键盘导航以实现可访问性,但我似乎无法让我的抽屉按钮获得键盘焦点。
设置 actionBarDrawerToggle(在 onCreate 中):
this.drawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
this.drawerLayout.setScrimColor(0x99000000);
this.actionBarDrawerToggle = new ActionBarDrawerToggle(this, this.drawerLayout, R.string.Root_Drawer, R.string.Root_Drawer);
this.actionBarDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_utilitybar_menu);
this.actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
this.drawerLayout.setDrawerListener(this.actionBarDrawerToggle);
Run Code Online (Sandbox Code Playgroud)
设置操作栏(也在 onCreate 中):
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(ACTIONBAR_BACKGROUND_COLOR)));
actionBar.setElevation(0);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
Run Code Online (Sandbox Code Playgroud)
操作栏上的其他按钮是可聚焦的,但我无法从这些按钮的最左侧向左(dpad 向左或键盘向左箭头)移动到主页按钮本身。对于这些按钮,我需要将它们标记为可聚焦以便让键盘导航到它们,例如(来自 onCreateOptionsMenu):
MenuItem alertItem = menu.add(0, R.id.menu_alert, 0, null);
alertItem.setActionView(this.alertIconActionView);
alertItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
this.alertIconActionView.setFocusable(true);
this.alertIconActionView.setFocusableInTouchMode(true);
Run Code Online (Sandbox Code Playgroud)
但是似乎没有我可以获得的主页按钮视图,可以让我将其设置为可聚焦元素。