How to get ActionBar view?

前端 未结 5 1294
野性不改
野性不改 2020-11-28 11:10

I\'m using the Showcase library to explain my application feature to the user. In some point I need to dim the whole ActionBar to present another

5条回答
  •  旧巷少年郎
    2020-11-28 11:51

    Yep. You can actually get the view by using this function:

    public View getActionBarView() {
        Window window = getWindow();
        View v = window.getDecorView();
        int resId = getResources().getIdentifier("action_bar_container", "id", "android");
        return v.findViewById(resId);
    }
    

    Pretty much the way this works is that the actionbar container uses the id android.R.id.action_bar_container, but this id is not public. Therefore we use getIdentifier() to retrieve this id and then the rest is simple.

提交回复
热议问题