[Android] Hack to make navigation drawer browsable with DPAD

Geoffrey Métais git at videolan.org
Fri Apr 8 18:10:26 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr  8 18:09:55 2016 +0200| [068711c189b6463094fca12629700942874398b8] | committer: Geoffrey Métais

Hack to make navigation drawer browsable with DPAD

> https://code.videolan.org/videolan/vlc-android/commit/068711c189b6463094fca12629700942874398b8
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 38b661e..64c3ad3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -38,6 +38,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
+import android.support.design.internal.NavigationMenuView;
 import android.support.design.widget.NavigationView;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -53,6 +54,7 @@ import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.SubMenu;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.FilterQueryProvider;
@@ -202,6 +204,16 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
                 if (getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder) instanceof MediaBrowserFragment)
                     ((MediaBrowserFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)).setReadyToDisplay(true);
             }
+
+            // Hack to make navigation drawer browsable with DPAD.
+            // see https://code.google.com/p/android/issues/detail?id=190975
+            // and http://stackoverflow.com/a/34658002/3485324
+            @Override
+            public void onDrawerOpened(View drawerView) {
+                super.onDrawerOpened(drawerView);
+                if(mNavigationView.requestFocus())
+                    ((NavigationMenuView)mNavigationView.getFocusedChild()).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
+            }
         };
 
         // Set the drawer toggle as the DrawerListener



More information about the Android mailing list