我的问题如下:我锁定了导航抽屉菜单setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN)
在平板电脑的横向模式下,但我需要右侧的片段处于活动状态,这样我就可以在导航始终打开的情况下单击它。但我不知道该怎么做。请帮忙。
您需要做以下几件事:
-
通过设置透明颜色来禁用布局褪色:
drawer.setScrimColor(Color.TRANSPARENT);
-
锁好抽屉
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
-
创建一个自定义抽屉类,允许在锁定模式下点击:
public class CustomDrawer extends DrawerLayout {
public CustomDrawer(Context context) {
super(context);
}
public CustomDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
View drawer = getChildAt(1);
if (getDrawerLockMode(drawer) == LOCK_MODE_LOCKED_OPEN && ev.getRawX() > drawer.getWidth()) {
return false;
} else {
return super.onInterceptTouchEvent(ev);
}
}
}
-
在 xml 中使用此类:
<com.example.myapplication.CustomDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
</FrameLayout>
<ListView android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"/>
</com.example.myapplication.CustomDrawer>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)