I started the project with a navigation box from the base Android Studio template. The only thing I did was show it as permanent in order to have a tablet / TV.
To achieve this, the only modification I made was in the xml layout. This allows NavView to always be visible.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="Content will come here" /> </LinearLayout> </LinearLayout>
I also put the project on Github, so anyone can test it.
PROJECT DEMO ON GITHUB
https://github.com/ChristopheVersieux/NavFocus
WHAT'S HAPPENING
My problem arises when I start to select items in a box using the D-pad. Once an item is selected, focus is completely lost. Trying to go back to the drawer and get focus seems very difficult, and I have to try several times using the left / right arrows
WHAT EXPECTED:
The box should hold focus, or the focus should be easily returned to the box.
WHAT DID I SAY:
I had the simplest idea to get the box to get focus again, but this code does not change anything:
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true);
Thank you very much for your help.
source share