gpt4 book ai didi

Android 底部导航查看项目文本颜色?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:32 26 4
gpt4 key购买 nike

我开始研究 Android 底部导航 View 。但我面临一个问题。如果我将 5 个项目添加到底部导航 View ,则只有选定的项目显示项目文本。如果我添加了 3 个项目,它工作正常。任何人请告诉我如何显示所有 5 个项目的项目文本。提前谢谢你。

菜单.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.reloadapp.reload.activity.IconTabsActivity">
<item
android:id="@+id/action_favorites"
android:enabled="true"
android:icon="@drawable/home_40"
android:title="Home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:enabled="true"
android:icon="@drawable/profile_40"
android:title="Profile"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:enabled="true"
android:icon="@drawable/reload_40"
android:title="Reload cash"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_musi"
android:enabled="true"
android:icon="@drawable/notifications"
android:title="Notifications"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_mus"
android:enabled="true"
android:icon="@drawable/menu_40"
android:title="More"
app:showAsAction="ifRoom" />
</menu>

依赖性: 编译 'com.android.support:appcompat-v7:25.0.1' 编译 'com.android.support:design:25.0.0'

 <android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@color/textColorPrimary"
app:menu="@menu/menu_icon_tabs"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimary"
android:layout_alignParentBottom="true">
</android.support.design.widget.BottomNavigationView>

最佳答案

移除底部导航中的动画,使用此代码

navigation = (BottomNavigationView) findViewById(R.id.navigation);
disableShiftMode(navigation);

方法

public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
//noinspection RestrictedApi
item.setShiftingMode(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}

更新:

您可以像这样更改菜单文字大小How to change the Menu text size

关于Android 底部导航查看项目文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43491741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com