英文:
how to change menu title color android java
问题
I need to change the title color of my menu on my drawer navigation activity.
This is part of my activity_main.xml
:
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/naView"
android:fitsSystemWindows="false"
android:background="@drawable/navbackground"
android:layout_gravity="start"
app:itemIconTint="@color/grayWhite"
app:headerLayout="@layout/navigationheader"
app:menu="@menu/menu">
And this is my activity_main_drawer.xml
: (this file is inside the menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/vibrationItem"
android:icon="@drawable/ic_baseline_vibration_24"
android:title="vibration" />
<item
android:id="@+id/Settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="Settings" />
</group>
<item android:title="others">
<menu>
<item android:title="Logout"
android:id="@+id/Logout"
android:icon="@drawable/logout"/>
</menu>
</item>
</menu>
This is what I get from my code, and how you see the "other" is displayed with a different color:
I saw many solutions on StackOverflow but I have not found a good solution for my problem.
英文:
I need to change the title color of my menu on my drawer navigation activity.
This is part of my activity_main.xml
:
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/naView"
android:fitsSystemWindows="false"
android:background="@drawable/navbackground"
android:layout_gravity="start"
app:itemIconTint="@color/grayWhite"
app:headerLayout="@layout/navigationheader"
app:menu="@menu/menu">
And this is my activity_main_drawer.xml
: (this file is inside the menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/vibrationItem"
android:icon="@drawable/ic_baseline_vibration_24"
android:title="vibration" />
<item
android:id="@+id/Settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="Settings" />
</group>
<item android:title="others">
<menu>
<item android:title="Logout"
android:id="@+id/Logout"
android:icon="@drawable/logout"/>
</menu>
</item>
</menu>
This is what I get from my code, and how you see the "other" is displayed with a different color:
I saw many solutions on StackOverflow but I have not found a good solution for my problem.
答案1
得分: 2
标题组的颜色基于应用程序主题中的 android:textColorSecondary
项定义的颜色。
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<item name="android:textColorSecondary">@color/....</item>
</style>
您可以使用以下代码覆盖 android:textColorSecondary
的颜色:
<com.google.android.material.navigation.NavigationView
android:theme="@style/ThemeOverlay.titleColor"
..>
使用以下代码块:
<style name="ThemeOverlay.titleColor" parent="">
<item name="android:textColorSecondary">@color/....</item>
</style>
英文:
The color of the title group is based on color defined by the android:textColorSecondary
item in your app theme.
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<item name="android:textColorSecondary">@color/....</item>
</style>
You can override the android:textColorSecondary
color with:
<com.google.android.material.navigation.NavigationView
android:theme="@style/ThemeOverlay.titleColor"
..>
with:
<style name="ThemeOverlay.titleColor" parent="">
<item name="android:textColorSecondary">@color/....</item>
</style>
答案2
得分: 0
去你的 `strings.xml` 文件中写入以下内容:
<string name="namestring"><font fgcolor='#YOUR_COLOR'>others</font></string>
现在前往你的 `menu.xml` 文件并将代码更改为以下内容:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/vibrationItem"
android:icon="@drawable/ic_baseline_vibration_24"
android:title="vibration" />
<item
android:id="@+id/Settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="Settings" />
</group>
<item android:title="@string/namestring">
<menu>
<item android:title="Logout"
android:id="@+id/Logout"
android:icon="@drawable/logout"/>
</menu>
</item>
</menu>
英文:
go to your strings.xml
file and write this:
<string name="namestring"><font fgcolor='#YOUR_COLOR'>others</font></string>
now go to your menu.xml
file and change your code to this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/vibrationItem"
android:icon="@drawable/ic_baseline_vibration_24"
android:title="vibration" />
<item
android:id="@+id/Settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="Settings" />
</group>
<item android:title="@string/namestring">
<menu>
<item android:title="Logout"
android:id="@+id/Logout"
android:icon="@drawable/logout"/>
</menu>
</item>
</menu>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论