Reputation: 314
I used
setTheme(R.style.Theme_AppCompat);
to set my app theme darker. Now I run into that issue that the selected item in my navigationbar is relativly dark, so that users can hardly see it.
Is there anything that I can use in my style to get the selected navigation item in another color? Here is a picture of it
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context="at.mrminemeet.asciimoji.MainActivity">
.....
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"/>
</android.support.constraint.ConstraintLayout>
Upvotes: 1
Views: 2109
Reputation: 884
Add the following to your BottomNavigationView:
app:itemIconTint="@drawable/bottom_navigation_selector"
app:itemTextColor="@drawable/bottom_navigation_selector"
In your drawable folder, create a file bottom_navigation_selector.xml and add this to it:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns :android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true"/>
<item android:color="@android:color/darker_gray" android:state_checked="false"/>
</selector>
Finally in every activity where you use this navigation bar add this line to onCreate() and onResume()
bottomNavigationView.setSelectedItemId(R.id.item);
Upvotes: 1
Reputation: 10971
You can specify the BottomNavigationView_itemBackground attribute to your BottomNavigationView, you can set a selector as a background with different colors for the normal and selected states
Upvotes: 0