public ToolbarActionBar(Toolbar toolbar, CharSequence title, Callback callback) { this.mDecorToolbar = new ToolbarWidgetWrapper(toolbar, false); this.mWindowCallback = new ToolbarCallbackWrapper(callback); this.mDecorToolbar.setWindowCallback(this.mWindowCallback); toolbar.setOnMenuItemClickListener(this.mMenuClicker); this.mDecorToolbar.setWindowTitle(title); }
@Nullable public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) { if (ab == null) return null; try { Field field = ab.getClass().getDeclaredField("mDecorToolbar"); field.setAccessible(true); ToolbarWidgetWrapper wrapper = (ToolbarWidgetWrapper) field.get(ab); field = ToolbarWidgetWrapper.class.getDeclaredField("mToolbar"); field.setAccessible(true); return (Toolbar) field.get(wrapper); } catch (Throwable t) { Log.d("ATEUtil", "Unable to get Toolbar from " + ab.getClass().getName()); return null; } }
@Nullable public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) { if (ab == null || !(ab instanceof WindowDecorActionBar)) return null; try { WindowDecorActionBar decorAb = (WindowDecorActionBar) ab; Field field = WindowDecorActionBar.class.getDeclaredField("mDecorToolbar"); field.setAccessible(true); ToolbarWidgetWrapper wrapper = (ToolbarWidgetWrapper) field.get(decorAb); field = ToolbarWidgetWrapper.class.getDeclaredField("mToolbar"); field.setAccessible(true); return (Toolbar) field.get(wrapper); } catch (Throwable t) { throw new RuntimeException("Failed to retrieve Toolbar from AppCompat support ActionBar: " + t.getMessage(), t); } }