how set navigation bar text color in android studio project
Posted 2025-02-14 19:21:01
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 ⇓
- Artificial Intelligence (AI)
- Cybersecurity
- Blockchain & Cryptocurrencies
- Internet of Things
- Cloud Computing
- Big Data & Analytics
- Virtual Reality
- 5G & Future Connectivity
- Robotics & Automation
- Software Development & Programming
- Tech Hardware & Devices
- Tech in Healthcare
- Tech in Business
- Gaming Technologies
- Tech in Education
- Machine Learning (ML)
- Blogging
- Affiliate Marketing
- Make Money
- Digital Marketing
- Product Review
- Social Media
- Excel
- Graphics design
- Freelancing/Consulting
- FinTech (Financial Technology)
- E-commerce and Digital Marketing
- Business
- Sport
- Self Development
- Tips to Success
- Video Editing
- Photo Editing
- Website Promotion
- YouTube
- Lifestyle
- Health
- Computer
- Phone
- Music
- Accounting
- Causes
- Networking
Read More
Why You Need a Monthly Financial Reporting Checklist As An Entrepreneurs
Setting up a Monthly Financial Reporting...
Tools for UI/UX Design
UI (User Interface) and UX (User Experience)...
Comprehensive Guide to HTML Attributes
HTML attributes provide additional information...
How to Make Money Through Passive Income & Investments
Here’s a comprehensive guide on making...
How to Build a Responsive Navbar with HTML, CSS, & JavaScript
Here’s a detailed guide on How to Build a...