3

我有一个工具栏,我想将背景更改为黑色,但默认情况下项目颜色为黑色,我想将其颜色更改为灰色,我该怎么做?非常感谢: 关于工具栏的我的图片

这是我的toolbar.xml

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2196F3"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

我的样式.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
4

2 回答 2

0

更改图标的色调属性。

通过 xml:

<item android:id="@+id/slash_toolbar" 
android:title="" 
android:icon="@drawable/ic_voice" 
app:showAsAction="always" 
android:tint="@android:color/white"/>

通过代码

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    for(int i = 0; i < menu.size(); i++){
        Drawable drawable = menu.getItem(i).getIcon();
        if(drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(getResources().getColor(R.color.textColorPrimary), PorterDuff.Mode.SRC_ATOP);
        }
    }

    return true;
}

要更改三个点的颜色,请将其放入 AppTheme 的 style.xml 中:

<!-- android:textColorSecondary is the color of the menu overflow icon (three vertical dots) -->
<item name="android:textColorSecondary">@color/white</item>
于 2019-05-30T15:13:49.040 回答
0

创建图标或矢量资源时,您可以选择颜色

在此处输入图像描述

单击颜色选择器。

如果要更改代码中的颜色,请添加app:iconTint="@color/yourcolor"MenuItem 以更改图标颜色。

<item
android:icon="@drawable/ic_share_white_24dp"
android:id="@+id/action_share"
android:title="@string/action_share"
android:orderInCategory="200"
app:iconTint="@color/yourcolor"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>

要更改 3 点图标颜色,请尝试将其添加到 styles.xml

<style name="YourCustomTheme.OverFlow">
    <item name="android:src">@drawable/my_overflow_image</item>
</style>
于 2019-05-30T15:10:25.297 回答