Растянуть BottomNavigationView на всю ширину
В xml разметку добавил BottomNavigationView, но почему-то он обрезан по бокам и текст не отображается.
Как сделать, чтобы он был растянут на всю ширину и можно ли уменьшить размер текста, чтобы текс и иконки всегда отображались?
Разметка
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical"
tools:context=".activity.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
app:itemBackground="@color/colorWhite"
app:menu="@menu/bottom_menu" />
</LinearLayout>
</LinearLayout>
Скриншот
Видно что BottomNavigationView не достает до краев, не могу понять почему.
Ответы (1 шт):
Вообще довольно странно поведение у вас я так вижу, потому что я вот попробовал вашу разметку у себя в коде:
по логике у вас должно быть приблизительно такое же поведение. Посмотрите на версии библиотек, может у вас старые библиотеки. Здесь вот есть документация по дизайну. Библиотеки такие:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
UPDATE
Ещё по поводу работы с пунктами меню, иконками и размером подписей. Чтобы подписи всегда отображались (я так думаю что вы это имели ввиду) нужно добавить параметр в xml виджета менюшки:
app:labelVisibilityMode="labeled"
чтобы можно сетить свои размеры, делаем два стиля:
<style name="BottomNavigationView" parent="@style/TextAppearance.AppCompat.Caption">
<item name="android:textSize">10sp</item>
</style>
<style name="BottomNavigationView.Active" parent="@style/TextAppearance.AppCompat.Caption">
<item name="android:textSize">11sp</item>
</style>
и подключаем к виджету:
app:itemTextAppearanceActive="@style/BottomNavigationView.Active"
app:itemTextAppearanceInactive="@style/BottomNavigationView"

