How to get ActionBar view?

前端 未结 5 1291
野性不改
野性不改 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:38

    I think this solution is more complete, handling both normal Activity and ActionBarActivity.

    It also handles the case that the actionbar was set using a toolbar, but you need to implement it in the activity you've created:

    public static View getActionBarView(final Activity activity) {
        if (activity instanceof IToolbarHolder)
            return ((IToolbarHolder) activity).getToolbar();
        final String packageName = activity instanceof ActionBarActivity ? activity.getPackageName() : "android";
        final int resId = activity.getResources().getIdentifier("action_bar_container", "id", packageName);
        final View view = activity.findViewById(resId);
        return view;
    }
    
    public interface IToolbarHolder {
        public android.support.v7.widget.Toolbar getToolbar();
    }
    

提交回复
热议问题