gpt4 book ai didi

android - 以编程方式设置工具栏图标颜色

转载 作者:太空宇宙 更新时间:2023-11-03 11:36:49 25 4
gpt4 key购买 nike

如何以编程方式设置 Toolbar/AppBarLayout 中图标(主页和溢出菜单图标)的颜色

我想为 Activity 中的单个 fragment 更改工具栏的配色方案。将 AppBarLayout 的背景设置为浅色(例如 appBarLayout.setBackgroundResource(..); 的浅灰色)导致白色图标和白色标题几乎不可见.

其布局如下:

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ToolbarStyle"
app:layout_scrollFlags="scroll|enterAlways"/>

</android.support.design.widget.AppBarLayout>

Solution found

最佳答案

支持 23 可以轻松更改溢出图标。这是来自 Lorne Laliberte answer 的方法

public static void setOverflowButtonColor(final Toolbar toolbar, final int color) {
Drawable drawable = toolbar.getOverflowIcon();
if(drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), color);
toolbar.setOverflowIcon(drawable);
}
}

您可以在传递自定义绘图时更改您的家..

getSupportActionBar().setHomeAsUpIndicator(R.drawable.your_drawable)

或者改变它的颜色

final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);

编辑:如果要换更多元素here是更改所有工具栏图标颜色的好帖子。

希望这对您有所帮助!

关于android - 以编程方式设置工具栏图标颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36020969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com