且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-10 12:25:44


  

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


块引用>

创建您自己的子类 ArrayAdapter ,你重写 areAllItemsEnabled()返回 isEnabled()返回真正假根据需要,code>。

I'm using the Navigation Drawer Example downloadable here.

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:

  1. 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
  2. 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.