我如何禁用 Material Design 底部导航菜单项?我可以设置
BottomNavigationView XML
.isClickable = false
,但这不会将该菜单项显示为已禁用,类似于按钮。我不能使用 .isEnabled
,因为 API 不允许这样做。BottomNavigationView 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" />
活动
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)
}
...