gpt4 book ai didi

android - 如何禁用底部导航 View 的菜单项?

转载 作者:行者123 更新时间:2023-12-02 13:19:32 24 4
gpt4 key购买 nike

如何禁用 Material 设计底部导航菜单项?我可以设置.isClickable = false但这不会将菜单项显示为禁用,类似于按钮。我做不到.isEnabled ,API 不允许。
底部导航 View XML

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/menu_item_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@color/colorDark"
app:menu="@menu/bottom_navigation_menu">
菜单 XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_home"
android:title="Home"
android:icon="@drawable/home_button"
app:showAsAction="ifRoom" />
Activity
class Something : AppCompatActivity() {
private lateinit var mHomeBtn: BottomNavigationItemView
override fun onCreate(...) {
mHomeBtn = this.findViewById(R.id.action_home)
mHomeBtn.isClickable = false // <--- will make it unable to click but won't show disabled
mHomeBtn.isEnabled = false // <--- will throw an error
mHomeBtn.setOnClickListener(this)
}
...

最佳答案

你应该得到你的BottomNavigationView的菜单。然后找到并禁用MenuItem你要的那个。在代码中可以按如下方式完成

override fun onCreate(savedInstanceState: Bundle?) {
// Find the bottom navigation view, (Use correct ID)
// menu_item_1 is probably not a good ID for a navigation view
val navView: BottomNavigationView = findViewById(R.id.nav_view)

// Find the menu item and then disable it
navView.menu.findItem(R.id.navigation_home).isEnabled = false
}

关于android - 如何禁用底部导航 View 的菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59700294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com