[英]Prevent android Navigation Drawer from closing till a condition is met
I have a NavigationDrawer having a list with many radio buttons.I want the user to have to select a list item before he can close the Drawer. 我有一个带有许多单选按钮的列表的NavigationDrawer。我希望用户在关闭抽屉之前必须选择一个列表项。
The drawer should not close till the item is selected. 在选择项目之前,抽屉不应关闭。
Is there a clean way with which I can achieve this?? 有一种干净的方式可以实现这个吗?
Set up the DrawerLayout lock mode setDrawerLockMode as follow: 设置DrawerLayout锁定模式setDrawerLockMode如下:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
but you need to handle actionbar home up button. 但你需要处理动作栏主页按钮。
I would recommend not restricting drawer operations, and just set a default selection, in case the user doesn't select an option. 我建议不要限制抽屉操作,只是设置默认选择,以防用户没有选择选项。
However, if you insist on doing it, this method seems to be the one to go with: 但是,如果你坚持这样做,这个方法似乎就是这样:
// Belonging to DrawerLayout
public void setDrawerLockMode (int lockMode, View drawerView)
In onCreate()
open it and lock it, then unlock it upon the selection of any of the options. 在
onCreate()
打开并锁定它,然后在选择任何选项时将其解锁。 There is no need to recheck during the usage, as radio implies there is always a selection, unlike check box selection. 在使用过程中无需重新检查,因为无线电意味着总有一个选择,与复选框选择不同。
That would be my first attempt at this, let me know, cheers. 这是我第一次尝试这个,让我知道,欢呼。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.