my nav panel I need to change bottom nav panel item's alpha, when choosing some element in it. For example, if i pick Documents, my documents fragment opens and the other elements in menu (Reader Mode and Settings) should be less bright. Guess i should use alpha property, but no idea how i do it. So finally menu should have this look: needed result
Menu code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@ id/documents"
android:title="Documents"
android:icon="@drawable/documents_icon" />
<item
android:id="@ id/reader_mode"
android:title="Reader Mode"
android:icon="@drawable/reader_mode_icon"/>
<item
android:id="@ id/settings"
android:title="Settings"
android:icon="@drawable/settings_icon"/>
</menu>
Some XML code:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e1e1e"
android:id="@ id/bottom_navigation_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/menu"
tools:ignore="MissingConstraints"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"/>
And code from .kt file:
class LyricsListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_lyrics_list)
bottom_navigation_menu.setOnNavigationItemReselectedListener {
when (it.itemId){
R.id.documents -> TODO()
}
}
}
}
CodePudding user response:
I think the best way to do change items is with darawable select let' say this the content of your documents_icon.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<!--your xml with color1 -->
</item>
<item android:state_selected="false">
<!--your xml with color2 -->
</item>
</selector>