Can the ActionBar drop-down navigation list control be disabled?

我怕爱的太早我们不能终老 提交于 2019-12-07 14:49:53

问题


I'm using a navigation control in the ActionBar to provide a drop-down list. I would like to disable selection of the drop down list under certain circumstances.

My layout for the closed view of the spinner adapter has a TextView wrapped in a LinearLayout. The best I've come up with is overriding getView in my spinner's adapter and making both the LinearLayout and TextView non-clickable and disabled. This has the effect of greying out the text but it can still be selected.

Edit I appreciate that I can hide the list but this is not what I want to do. Furthermore I have returned false in the methods which check if one or all items are enabled but this does not work.

Trying to get this working with Honeycomb on a Xoom. Thanks in advance. Peter.


回答1:


If you want to prevent selection of anything in the list navigation mode, call setNavigationMode(NAVIGATION_MODE_STANDARD) and get rid of it entirely until you are ready for it to be used again.

If you want to prevent selection of specific items in the list navigation mode, have your SpinnerAdapter implement areAllItemsEnabled() to return false and implement isItemEnabled() to return true or false as needed -- I haven't tried this, but in theory it should work.




回答2:


You can create a custom view in your ActionBar like so:

    ViewGroup customFilterBrowse = (ViewGroup) getLayoutInflater().inflate(R.layout.component_cancellable_progressbar, null);       
    ActionBar actionBar = getActionBar();
    actionBar.setCustomView(customFilterBrowse);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);   

You can make the custom view do whatever you want (You can create a Spinner component which you disable in certain circumstances for instance).

HTH



来源:https://stackoverflow.com/questions/6451017/can-the-actionbar-drop-down-navigation-list-control-be-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!