1

I have developed an app based on the "Navigation Drawer Activity" template in Android Studio. However, I have now discovered that it is not possible to open the navigation drawer with a bluetooth keyboard.

At first I thought I deleted code by mistake but when I created a new project and compiled it without any changes I found out that the navigation drawer is indeed not operable with the keyboard. I also tried all possible key combinations. Without success.

As I am not yet that experienced in programming, I am not sure how to solve this problem.

As far as I understand the code of the template, the following code in the MainActivity.java would have to be modified to solve the problem.

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    mAppBarConfiguration = new AppBarConfiguration.Builder(
            R.id.nav_home, R.id.contactFragment, R.id.imageFragment, R.id.editFieldFragment, R.id.headersFragment, R.id.contrastFragment, R.id.imageButtonFragment, R.id.tabOrderFragment)
            .setDrawerLayout(drawer)
            .build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
    NavigationUI.setupWithNavController(navigationView, navController);
}

You can find the complete project here AccessibilityDemo if you need it.

Can someone please help me solve this problem?

Many thanks in advance.

Kind regards

Petra Ritter

Syed Rafaqat Hussain
  • 1,009
  • 1
  • 9
  • 33
  • Have you seen the various answers to: [Android Accessibility - Unable to focus on any element in the Appbar](https://stackoverflow.com/q/49200720/295004) – Morrison Chang May 22 '21 at 11:52

1 Answers1

0

You can assign a key to toggle the nav menu manually, although this wouldn't be in line with consistant navigation. I generated a new NavDrawer Project becuase I couldn't get your code to run on my machine.

private fun toggleNav() {
    if (binding.drawerLayout.isDrawerOpen(binding.navView)) {
        binding.drawerLayout.close()
    } else {
        binding.drawerLayout.open()
    }
}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
    return when (keyCode) {
        KeyEvent.KEYCODE_TAB -> {
            toggleNav()
            true
        }
        else -> super.onKeyUp(keyCode, event)
    }
}

You would probably find keyboard users using the Switch Access accessibility service, which works a lot like TalkBack, but without the audio feedback. In this case they would probably highlight the nav menu icon and activate it in much the same way a TalkBack user would, but with tabs and selections instead of swipes and double taps.

It is interesting to note that in the TalkBack and Switch Access modes, closing the menu (without a keyboard) is next to impossible. It should probably go on the issue tracker.

I also had a look at Google's keyboard navigation guide, and they don't seem to have a keyboard shortcut for opening the nav bar.

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
  • 1
    I have now solved it according to this post https://stackoverflow.com/questions/49200720/android-accessibility-unable-to-focus-on-any-element-in-the-appbar . However, this solution has the disadvantage that it is hardly recognisable when the button to open the drawer navigation has the keyboard focus. I probably have to define a key combination after all. Unless someone has idea how to make the keyboard focus better visible – Petra Ritter Jun 04 '21 at 09:04
  • The best thing you can do is test with users. See what they would expect – Quintin Balsdon Jun 04 '21 at 09:20