我在我的代码中使用这个 GitHub 库进行底部导航。芯片导航栏 在启动程序后我试图让它浮起来。但是当运行程序时它消失了但是当点击按钮的地方时。点击监听器工作,但我看不到导航栏这是点击监听器;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btmNav = findViewById(R.id.btmNav);
layout = findViewById(R.id.cntBTM);
animMove = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
btmNav.startAnimation(animMove);
//////////////*
if (savedInstanceState == null) {
NewsFragment newsFragment = new NewsFragment();
fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, newsFragment)
.commit();
}
btmNav.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() {
@Override
public void onItemSelected(int id) {
Fragment fragment = null;
switch (id) {
case R.id.home:
fragment = new WebFragment();
break;
case R.id.activity:
fragment = new ActivityFragment();
break;
case R.id.settings:
fragment = new SettingFragment();
break;
}
if (fragment != null) {
fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, fragment)
.commit();
} else {
Log.e(TAG, "Error in creating fragment");
}
}
});
这在主要活动中
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="@+id/btmNav"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_margin="12dp"
android:background="@drawable/rounded"
android:elevation="5dp"
android:outlineAmbientShadowColor="@color/colorAccent"
app:cnb_menuResource="@menu/bottom_menu"
app:cnb_unselectedColor="#fff"