When drawer opens, always place focus at it's start
This commit is contained in:
parent
54ceb85ebe
commit
850f51a156
1 changed files with 1 additions and 26 deletions
|
@ -21,13 +21,10 @@ import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.view.GravityCompat;
|
|
||||||
import androidx.core.view.ViewCompat;
|
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -111,28 +108,6 @@ public final class FocusAwareDrawerLayout extends DrawerLayout {
|
||||||
public void openDrawer(@NonNull final View drawerView, final boolean animate) {
|
public void openDrawer(@NonNull final View drawerView, final boolean animate) {
|
||||||
super.openDrawer(drawerView, animate);
|
super.openDrawer(drawerView, animate);
|
||||||
|
|
||||||
LayoutParams params = (LayoutParams) drawerView.getLayoutParams();
|
drawerView.requestFocus(FOCUS_FORWARD);
|
||||||
|
|
||||||
int gravity = GravityCompat.getAbsoluteGravity(
|
|
||||||
params.gravity, ViewCompat.getLayoutDirection(this));
|
|
||||||
|
|
||||||
int direction = 0;
|
|
||||||
|
|
||||||
switch (gravity) {
|
|
||||||
case Gravity.LEFT:
|
|
||||||
direction = FOCUS_LEFT;
|
|
||||||
break;
|
|
||||||
case Gravity.RIGHT:
|
|
||||||
direction = FOCUS_RIGHT;
|
|
||||||
break;
|
|
||||||
case Gravity.TOP:
|
|
||||||
direction = FOCUS_UP;
|
|
||||||
break;
|
|
||||||
case Gravity.BOTTOM:
|
|
||||||
direction = FOCUS_DOWN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawerView.requestFocus(direction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue