Unable to navigate from app bar after setting focusable attribute

Issue

I am creating a very simple WebView app with a few useful links and I want the initial focus to be on the app bar with easy access to the menu. This works if I add focusable attributes to the layout in main.xml

android:focusable"true"
android:focusableInTouchMode"true"

However I’m unable to navigate away from the app bar to the WebView content below unless I add requestFocus to the menu actions:

case R.id.url:
webView.loadUrl("https://example.com");
webView.requestFocus();

Then I can navigate down to the WebView content below, but as soon as I return to the app bar navigation is lost again. How can I freely navigate away from the app bar?

Solution

So I added the following code to main.xml and it solves my issue

android:nextFocusDown"@+id/webview"

Answered By – Brenton

Leave a Comment