【发布时间】:2020-01-18 23:53:29
【问题描述】:
我有一个包含 4 个项目的 BottomNavigationBar,我希望可以检查多个项目。我知道这个栏是用来浏览活动的,但我希望不止一项是chackable
如果不可检查,至少单独更改项目的文本颜色或图标颜色,而不是整体更改它们
代码
final BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
bottomNavigation.getMenu().setGroupCheckable(0, true, true);
BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.vpn:
bottomNavigation.getMenu().findItem(R.id.home).setVisible(false);
bottomNavigation.getMenu().findItem(R.id.home).setChecked(true);
bottomNavigation.getMenu().findItem(R.id.theme).setTitle("ON");
Toast.makeText(getApplicationContext(),"VPN",Toast.LENGTH_SHORT).show();
return true;
case R.id.incognito:
Toast.makeText(getApplicationContext(),"Private",Toast.LENGTH_SHORT).show();
return true;
case R.id.theme:
Toast.makeText(getApplicationContext(),"Theme",Toast.LENGTH_SHORT).show();
return true;
case R.id.home:
Toast.makeText(getApplicationContext(),"Home",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
bottomNavigation.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
xml 代码
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/black"
android:theme="@style/BottomNavigationTheme"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_navigation_menu"/>
Style.xml
<style name="BottomNavigationTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
【问题讨论】:
标签: java android checkbox colors navigation