how set navigation bar text color in android studio project

0
441

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!

Search
Sellect from all Categories bellow ⇓
Read More
Accounting
Why You Need a Monthly Financial Reporting Checklist As An Entrepreneurs
Setting up a Monthly Financial Reporting...
By flowisetech 2025-04-13 20:06:50 0 46
UI/UX
Tools for UI/UX Design
UI (User Interface) and UX (User Experience)...
By flowisetech 2025-02-21 08:57:10 0 403
HTML
Comprehensive Guide to HTML Attributes
HTML attributes provide additional information...
By flowisetech 2025-02-19 12:39:18 0 379
E-commerce and Digital Marketing
How to Make Money Through Passive Income & Investments
Here’s a comprehensive guide on making...
By flowisetech 2025-02-17 20:56:13 0 416
HTML
How to Build a Responsive Navbar with HTML, CSS, & JavaScript
Here’s a detailed guide on How to Build a...
By flowisetech 2025-03-07 09:11:46 0 381