选择项目后不会显示项目图标

时间:2021-06-06 13:12:43

标签: java android xml kotlin bottomnavigationview

我正在使用 this 库来制作相同的底部导航,但是当我点击项目时,图标会消失,这是我的代码

activity_main:

<com.github.kwasow.bottomnavigationcircles.BottomNavigationCircles
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:forceDarkAllowed="true"
    app:labelVisibilityMode="selected"
    app:menu="@menu/navigation" />

导航项:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/destination_ejournal"
    android:icon="@drawable/ejournal_selector"

    android:title="@string/bottomnav_ejournal" />

<item
    android:id="@+id/destination_solah"
    android:icon="@drawable/solah_selector"
    android:title="@string/bottomnav_solah" />

<item
    android:id="@+id/destination_home"
    android:icon="@drawable/home_selector"
    android:title="@string/bottomnav_home" />

<item
    android:id="@+id/destination_dua"
    android:icon="@drawable/dua_selector"
    android:title="@string/bottomnav_dua" />

<item
    android:id="@+id/menu_more"
    android:icon="@drawable/more_selector"
    android:title="@string/bottomnav_more" />

主要活动:

val bottomNavigation = findViewById<BottomNavigationCircles>(R.id.navigation)
    bottomNavigation.color = Color.WHITE

那我在这里做错了什么?

是在活动中还是在 XML 中?

问题图片:

If i click Home

If i navigate to another

If i change color from white to red

主页选择器:

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/home_selected" android:state_checked="true" />
 <item android:drawable="@drawable/ic_home" android:state_checked="false" />

</selector>

ic_home: 是 verctor home_selected: 是 png

解决方案:

如果“state_checked”和其中一个是 PNG 格式,我使用选择器来显示不同的可绘制对象,所以它没有出现,我使用了 2 个向量作为选择器,现在工作正常


1 个答案:

答案 0 :(得分:0)

我用那个库试过你的例子,问题是你在运行时将颜色设置为白色,这种混合到底部导航颜色中。

您可以尝试不同的颜色,例如红色。

val bottomNavigation = findViewById<BottomNavigationCircles>(R.id.navigation)
bottomNavigation.color = Color.RED

它给了我以下结果:

botton nav

相关问题