Метки не эллипсированные в BottomNavigationView - PullRequest
0 голосов
/ 08 октября 2018

У меня есть макет с BottomNavigationView с атрибутом app:labelVisibilityMode, установленным на labeled:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/navigation" />

</FrameLayout>

Меню состоит из пяти пунктов:

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

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_navigation"
        android:title="Short" />

    <item
        android:id="@+id/navigation_notifications_1"
        android:icon="@drawable/ic_navigation"
        android:title="Short" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_navigation"
        android:title="Longer text123" />

    <item
        android:id="@+id/navigation_notifications_2"
        android:icon="@drawable/ic_navigation"
        android:title="Short" />

    <item
        android:id="@+id/navigation_notifications_3"
        android:icon="@drawable/ic_navigation"
        android:title="Short" />

</menu>

Есть проблемас третьим элементом с более длинной меткой ("Longer text123") - второе слово не имеет эллипсиса, а просто не отображается:

enter image description here

Создание меткинемного короче вызывает правильное поведение:

enter image description here

Есть ли способ обработки более длинных этикеток?Лучшим решением было бы сделать его эллиптическим и отобразить «Более длинный текст ...», когда нет места для всего текста.

Ответы [ 2 ]

0 голосов
/ 31 декабря 2018
 <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|start"
        app:itemIconTint="@color/color_c3c3c3"
        app:itemTextColor="@color/color_aaaaaa"
        android:textSize="@dimen/_13sdp"
        app:menu="@menu/nav_bottom" />

попробуйте

0 голосов
/ 31 декабря 2018

У меня была такая же проблема и я много искал.Наконец я получил решение для добавления в код.Просто добавьте следующие строки в ваш код.

 BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigation.getChildAt(0);
    for (int i = 0; i < menuView.getChildCount(); i++) {
        BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
        View activeLabel = item.findViewById(R.id.largeLabel);
        if (activeLabel instanceof TextView) {
            activeLabel.setPadding(0, 0, 0, 0);
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...