[英]How do i set transparency(alpha) to bottom menu items kotlin
my nav panel I need to change bottom nav panel item's alpha, when choosing some element in it.我的导航面板在选择其中的某些元素时,我需要更改底部导航面板项目的 alpha。 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.
猜猜我应该使用 alpha 属性,但不知道我是怎么做的。 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:一些 XML 代码:
<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:以及来自 .kt 文件的代码:
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()
}
}
}
}
I think the best way to do change items is with darawable select let' say this the content of your documents_icon.xml我认为更改项目的最佳方法是使用 darawable 选择让我们说您的文档_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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.