禁用于Android的一个抽屉式导航栏项目项目、抽屉式、Android

2023-09-06 10:12:10 作者:可笑的木偶戏

我在这里使用导航抽屉例下载

我想扩展这个例子来禁用行星之一的选择。为简单起见,可以说,我要永久禁用土星的选择,改变土星暗灰色的文字,并有当用户选择它,它不突出。 (在现实中,我想以编程方式禁用导航当用户还没有保存到设备屏幕上改变某些值)。

我已经得到了这个最接近的事就是从被称为在 onItemClick 点击监听器,而是一个问题仍然是即使我做到这一点 - 土星的文本,当用户点击它似乎仍然选择和亮点。

哪一部分的窗口小部件,我需要土星的文本被突出显示更改为prevent?结果我试着改变

  mDrawerLayout.setClickable(假);mDrawerList.setClickable(假); 

但没有这些选项会出现有任何的影响。

任何建议或想法,如何处理这个问题呢?一对夫妇有用的注意事项:

我知道,或者我可以Set抽屉锁定模式以prevent被打开抽屉式导航栏中,但是这是直观远远低于已经变灰导航动作是比较合适的事情,在这里做去除不能在这个时候访问列表中的项目?类似在删除ListView的实施的这里?这个最大的缺点是,我可能不得不改变列表视图来描述的为什么的项目已经从该列表中暂时删除。解决方案   

我想扩展这个例子来禁用行星之一的选择

创建您自己的子类 ArrayAdapter ,你重写 areAllItemsEnabled()返回 isEnabled()返回真正假。

I'm using the Navigation Drawer Example downloadable here.

Android P导航栏合成一颗虚拟键 增加免打扰模式

I'd like to extend this example to disable the selection of one of the planets. For simplicity, lets say I want to permanently disable the selection of Saturn, and change the text of Saturn to dark gray, and have it not highlight when a user selects it. (in reality, I would like to disable navigation programmatically when a user has changed certain values on the screen not yet saved to the device).

The closest thing I've gotten to this is to stop the selectItem() method from being called from within the onItemClick click listener, but an issue remains even if I do this - the text of "Saturn" still appears selectable and highlights when a user clicks it.

What portion of the widgets do I need to change to prevent the text of Saturn from being highlighted? I've tried changing

mDrawerLayout.setClickable(false);
mDrawerList.setClickable(false);

But neither of these options appear to have any affect.

Any suggestions or ideas as to how to approach this problem? A couple helpful notes:

I'm aware that alternatively I can Set the Drawer Lock Mode to prevent the navigation drawer from being opened, but this is much less intuitive than having grayed out nav actions Is the more appropriate thing to do here to remove the items from the list that cannot be accessed at this time? Similar to as described in the Remove ListView implementation here? The biggest disadvantage to this is that I would probably have to change the listview to describe why items have been removed from this list temporarily.

解决方案

I'd like to extend this example to disable the selection of one of the planets

Create your own subclass of ArrayAdapter where you override areAllItemsEnabled() to return false and isEnabled() to return true or false as needed.