简体   繁体   English

如何将透明度(alpha)设置为底部菜单项kotlin

[英]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.

相关问题 如何设置列表视图中所有项目的 alpha? - How do I set the alpha of all items in a listview? 将顶部的 alpha 设置为 0%,将底部的 alpha 设置为 70% - Android - Kotlin - Set alpha on top to 0 percent and on bottom to 70 percent - Android - Kotlin android-如何在底部导航视图的中间设置菜单项? - android - How to set menu items in the middle in a Bottom Navigation View? 如何在NavigationDrawerActivity中的左侧菜单上设置透明度 - How set transparency onleft side menu in NavigationDrawerActivity 如何设置在Android菜单xml文件中定义的菜单项的意图? - How do I set the intent of menu items defined in an Android menu xml file? 如何通过动画设置Android View的透明度? - How do I set an Android View's transparency with animation? 仅当单击底部菜单项并仍然使用 setupWithNavController 时,我们如何处理底部菜单导航项单击? - How do we handle bottom menu nav items clicks only when bottom menu items are clicked and still use setupWithNavController? 如何访问菜单项? - How do I access menu items? 如何在ActionBar中放置菜单项? - How do I position menu items in ActionBar? 如何在Kotlin中设置单个菜单项的文本颜色? - How can I set the text color of an individual menu item in Kotlin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM