Java
how set navigation bar text color in android studio project

To set the text color for the navigation bar in your Android Studio project, you can modify it using XML styles or programmatically in your Java/Kotlin code. Here's how you can do it:
1. Using XML Styles
You can customize the colorPrimary
, colorOnPrimary
, or action bar text color in your res/values/themes.xml
or styles.xml
file.
<resources>
<style name="AppTheme" parent="Theme.Material3.Light.NoActionBar">
<!-- Set the navigation bar color -->
<item name="android:navigationBarColor">@color/your_color</item>
<!-- Set the text color on the navigation bar -->
<item name="android:textColorPrimary">@color/your_text_color</item>
</style>
</resources>
- Replace
@color/your_color
with the color resource or hex code you want for the background. - Replace
@color/your_text_color
with the desired color for the text on the navigation bar.
2. Programmatically in Java/Kotlin
You can also set the navigation bar and its text color programmatically in your activity.
Kotlin
window.navigationBarColor = ContextCompat.getColor(this, R.color.your_color)
Java
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.your_color));
If you want to set the text/icon color for the navigation bar:
- For light text/icons: Use
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
. - For dark text/icons: Use
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
.
Kotlin Example
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
Java Example
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
3. Customizing Bottom NavigationView (if applicable)
If you're using a BottomNavigationView
, set the text color in res/color/selector.xml
and apply it in your menu
resource.
Selector XML (res/color/nav_text_color.xml
)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/active_color" android:state_checked="true" />
<item android:color="@color/inactive_color" />
</selector>
Apply to Menu (res/menu/bottom_nav_menu.xml
)
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home"
android:title="@string/home"
app:itemTextColor="@color/nav_text_color"
app:itemIconTint="@color/nav_text_color" />
This will change the text and icon color dynamically for selected and unselected states.
Let me know if you need more clarification!