0

我在我的代码中使用这个 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"
4

2 回答 2

1

使用这个库https://github.com/ismaeldivita/chip-navigation-bar

不要忘记在 settings.graddle 中添加 maven

maven { url 'https://jitpack.io' }

并且不要忘记将此依赖项添加到您的 build.graddle 文件中

    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.0'
于 2021-12-17T23:52:26.317 回答
0

添加你的build.gradle implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'

于 2020-05-09T17:56:32.423 回答