我正在努力实现上述设计。我可以更改图标,但无法更改底部文本。我使用材质底部导航栏
我通过为每个图标实现单独的选择器可绘制对象来实现图标更改。有什么方法可以对导航标题做同样的事情吗?
MainActivity.class
public class MainActivity extends AppCompatActivity {
BottomNavigationView navView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_saved, R.id.navigation_applied, R.id.navigation_profile, R.id.navigation_more)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
}
Run Code Online (Sandbox Code Playgroud)
活动主文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) android material-design bottomnavigationview android-bottomnav android-bottom-nav-view
android ×2