gpt4 book ai didi

android - 项目 BottomNavigationView 的裁剪标题

转载 作者:行者123 更新时间:2023-11-29 23:26:45 24 4
gpt4 key购买 nike

当使用设计库 'com.android.support:design:28.0.0' BottomNavigationView 错误地显示带有长文本的项目标题时:

enter image description here我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mvp.ui.activities.MainActivity">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="56dp"
android:layout_above="@+id/navigation"
android:id="@+id/fragmentContent" />

<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
app:labelVisibilityMode="labeled"
app:itemHorizontalTranslationEnabled="false"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

这看起来很奇怪,因为使用设计库 com.android.support:design:27.1.1 时完全相同的代码会产生很好的结果:

enter image description here

这怎么可能?对于新版本的库,我尝试使用 labelVisibilityMode,但这没有帮助。

app:showAsAction="always" 也不起作用。有什么想法吗?

最佳答案

更新素材库后需要使用navigation_bar_item_large_label_view 而不是 R.id.largeLabel

public void removePaddingFromNavigationItem() {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);

for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
View activeLabel = item.findViewById(R.id.navigation_bar_item_large_label_view);
if (activeLabel instanceof TextView) {
activeLabel.setPadding(0, 0, 0, 0);
}
}

关于android - 项目 BottomNavigationView 的裁剪标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53420239/

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