工具栏中的导航图标颜色没有改变?
Navigation icon color in toolbar is not changing?
我有一个添加了导航图标的 Material 工具栏。但是,当我尝试更改导航图标颜色时,更改在布局验证中可见,但在我 phone.
上安装应用程序时却看不到
这是link工具栏照片toolbar image
这是 xml 布局:
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title="Title Text"
app:menu="@menu/main_activity"
android:background="@color/color_toolbar"
app:titleTextColor="@color/titleTextColor"
app:navigationIcon="@drawable/ic_baseline_dehaze"
app:navigationIconTint="@color/white"
android:layout_height="wrap_content"/>
可绘制的导航图标 (@drawable/ic_baseline_dehaze):
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M2,15.5v2h20v-
2L2,15.5zM2,10.5v2h20v-2L2,10.5zM2,5.5v2h20v-2L2,5.5z"/>
</vector>
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private MaterialToolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);;
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIconTint(getResources().getColor(R.color.white));
}
}
这里是themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NewApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/highlight</item>
<item name="colorPrimaryVariant">@color/action_mode</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/checkIconselected</item>
<item name="colorSecondaryVariant">@color/checkIconselected</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#00766a</item>
<!-- Customize your theme here. -->
<item name="actionModeBackground">@color/action_mode</item>
<item name="windowActionModeOverlay">true</item>
</style>
这里是colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="color_toolbar">#075e54</color>
<color name="activityBackground">#ffffff</color>
<color name="titleTextColor">#ffffff</color>
<color name="highlight">#075e54</color>
<color name="selected">#8A354239</color>
<color name="checkIconselected">#25D366</color>
<color name="transparent">#00FFFFFF</color>
<color name="action_mode">#00897b</color>
<color name="toolbar_bg">#8A000000</color>
<color name="tab_indicator">#ffffff</color>
<color name="white_black">#000000</color>
</resources>
因此,如果您看到我已经更改了 drawable 和 activity.java 中的导航图标颜色,颜色仍然没有改变。谁能告诉我我做错了什么?
您可以将此行添加到您的样式中:
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
或使用此项目创建另一种样式并将其设置为工具栏:
<style name="ToolbarColor" parent="AppTheme">
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title="Title Text"
app:menu="@menu/main_activity"
android:background="@color/color_toolbar"
app:titleTextColor="@color/titleTextColor"
app:navigationIcon="@drawable/ic_baseline_dehaze"
app:navigationIconTint="@color/white"
android:layout_height="wrap_content"/
app:theme="@style/ToolbarColor">
您也可以设置 colorControlNormal
而不是 android:textColorSecondary
我有一个添加了导航图标的 Material 工具栏。但是,当我尝试更改导航图标颜色时,更改在布局验证中可见,但在我 phone.
上安装应用程序时却看不到这是link工具栏照片toolbar image
这是 xml 布局:
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title="Title Text"
app:menu="@menu/main_activity"
android:background="@color/color_toolbar"
app:titleTextColor="@color/titleTextColor"
app:navigationIcon="@drawable/ic_baseline_dehaze"
app:navigationIconTint="@color/white"
android:layout_height="wrap_content"/>
可绘制的导航图标 (@drawable/ic_baseline_dehaze):
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M2,15.5v2h20v-
2L2,15.5zM2,10.5v2h20v-2L2,10.5zM2,5.5v2h20v-2L2,5.5z"/>
</vector>
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private MaterialToolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);;
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIconTint(getResources().getColor(R.color.white));
}
}
这里是themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NewApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/highlight</item>
<item name="colorPrimaryVariant">@color/action_mode</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/checkIconselected</item>
<item name="colorSecondaryVariant">@color/checkIconselected</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#00766a</item>
<!-- Customize your theme here. -->
<item name="actionModeBackground">@color/action_mode</item>
<item name="windowActionModeOverlay">true</item>
</style>
这里是colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="color_toolbar">#075e54</color>
<color name="activityBackground">#ffffff</color>
<color name="titleTextColor">#ffffff</color>
<color name="highlight">#075e54</color>
<color name="selected">#8A354239</color>
<color name="checkIconselected">#25D366</color>
<color name="transparent">#00FFFFFF</color>
<color name="action_mode">#00897b</color>
<color name="toolbar_bg">#8A000000</color>
<color name="tab_indicator">#ffffff</color>
<color name="white_black">#000000</color>
</resources>
因此,如果您看到我已经更改了 drawable 和 activity.java 中的导航图标颜色,颜色仍然没有改变。谁能告诉我我做错了什么?
您可以将此行添加到您的样式中:
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
或使用此项目创建另一种样式并将其设置为工具栏:
<style name="ToolbarColor" parent="AppTheme">
<item name="android:textColorSecondary">INSERT_COLOR_HERE</item>
</style>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title="Title Text"
app:menu="@menu/main_activity"
android:background="@color/color_toolbar"
app:titleTextColor="@color/titleTextColor"
app:navigationIcon="@drawable/ic_baseline_dehaze"
app:navigationIconTint="@color/white"
android:layout_height="wrap_content"/
app:theme="@style/ToolbarColor">
您也可以设置 colorControlNormal
而不是 android:textColorSecondary