Fixed focus pinned nav menu

pull/207/head
M66B 2 years ago
parent 107c50f832
commit 31654795bc

@ -25,11 +25,16 @@ import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import java.util.ArrayList;
public class DrawerLayoutEx extends DrawerLayout {
public DrawerLayoutEx(@NonNull Context context) {
super(context);
@ -89,4 +94,20 @@ public class DrawerLayoutEx extends DrawerLayout {
return super.dispatchGenericMotionEvent(ev);
}
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
if (getDrawerLockMode(Gravity.LEFT) == LOCK_MODE_LOCKED_OPEN) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child.getVisibility() == View.VISIBLE && isContentView(child))
child.addFocusables(views, direction, focusableMode);
}
} else
super.addFocusables(views, direction, focusableMode);
}
boolean isContentView(View child) {
return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
}
}

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:descendantFocusability="blocksDescendants"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true">

Loading…
Cancel
Save