android动态改变菜单栏,android-如何在不设置样式栏的情况下动态更...

我在这里面临着同样的问题.我为ToolBar的元素做了什么:

>对于背景颜色:toolbar.setBackgroundColor(Color.parseColor(“#xxxxxxxx”));

>对于文本颜色:toolbar.setTitleTextColor(Color.parseColor(“#xxxxxxxx”));

>对于汉堡/抽屉按钮:

int color = Color.parseColor("#xxxxxxxx");

final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);

for (int i = 0; i < toolbar.getChildCount(); i++){

final View v = toolbar.getChildAt(i);

if(v instanceof ImageButton) {

((ImageButton)v).setColorFilter(colorFilter);

}

}

>对于ActionMenuItemView(工具栏的按钮,包括溢出按钮):

private void colorizeToolBarItem(AppCompatActivity activity, final PorterDuffColorFilter colorFilter, final String description) {

final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();

final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();

viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

final ArrayList outViews = new ArrayList<>();

decorView.findViewsWithText(outViews, description,

View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);

if (outViews.isEmpty())

return;

ActionMenuItemView overflow = (ActionMenuItemView)outViews.get(0);

overflow.getCompoundDrawables()[0].setColorFilter(colorFilter);

removeOnGlobalLayoutListener(decorView,this);

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值