android toolbar overflow icon color

来源:互联网 发布:windows 守护进程 编辑:程序博客网 时间:2024/06/06 21:42
    /**     * Change android toolbar overflow icon color     * @param activity:activity     * @param color:your want to color     * @link http://stackoverflow.com/questions/26997231/android-lollipop-material-design-overflow-menu-icon-color     */    public static void setOverflowButtonColor(final Activity activity, final int color) {        final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);        final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();        if (decorView==null)return;        final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();        if (viewTreeObserver==null)return;        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {            @Override            public void onGlobalLayout() {                final ArrayList<View> outViews = new ArrayList<View>();                decorView.findViewsWithText(                        outViews,                        overflowDescription,                        View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);                if (outViews.isEmpty()) {                    return;                }                try {                    AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);                    if (overflow != null) {                        overflow.setColorFilter(color);                    }                    if (Build.VERSION.SDK_INT < 16) {                        decorView.getViewTreeObserver().removeGlobalOnLayoutListener(this);                    } else {                        decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);                    }                } catch (Exception e) {                }            }        });    }



link:

http://stackoverflow.com/questions/26997231/android-lollipop-material-design-overflow-menu-icon-color

0 0
原创粉丝点击