Can't find action bar (Sherlock) inside root view

烂漫一生 提交于 2019-12-11 10:38:19

问题


I'm trying to find my activity's Action Bar's spinner so I can selectively show and hide it (setNavigationMode does not work for my purposes). I tried this code, but the Action Bar doesn't appear to be in my activity's (which is an extension of SherlockFragmentActivity) root view.

private View findActionBarSpinner() {
    View rootView = findViewById(android.R.id.content).getRootView();
    List<View> spinners = traverseViewChildren( (ViewGroup) rootView );
    return findListNavigationSpinner(spinners); // implement according to your layouts
}

All I get for rootView is a FrameLayout containing the RelativeLayout defined in my layout file (with only the elements within). I don't see anything that looks like an Action Bar or a spinner, and and sure enough traverseViewChildren (in the link above) returns an empty list.

I also tried, in the spirit of this answer, View rootView = getWindow().getDecorView().findViewById(android.R.id.content).getRootView();. The result was the same.

I'm making the call to findActionBarSpinner inside onOptionsItemSelected. (Though I can't access it, the action bar is fully visible and working properly at this point, so I doubt it's an issue of trying to access it at the wrong part of lifecycle.)

Any ideas?

来源:https://stackoverflow.com/questions/18343844/cant-find-action-bar-sherlock-inside-root-view

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