BottomNavigationView隐藏标题只放大一个图标android
Hide title and enlarge only one icon in BottomNavigationView android
我需要制作一个自定义的 BottomNavigationView,中间有一个更大的图标,没有标题,如下图所示,其他图标大小正常,每个图标下方都有一个标题图标。
我正在使用 android 导航组件库。
如何实现?
我的activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.MainActivity">
<fragment
android:id="@+id/main_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
android:background="#FFF"
app:itemIconTint="@drawable/nav_item_color_state"
app:itemTextColor="@drawable/nav_item_color_state"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/main_navigation_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
和main_navigation_menu
<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">
<item
android:id="@+id/billFragment"
android:checkable="true"
android:icon="@drawable/ic_bill"
android:title="@string/bill"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/paymentsFragment"
android:checkable="true"
android:icon="@drawable/ic_payments"
android:title="@string/payments"
app:showAsAction="always" />
<item
android:id="@+id/cachedFragment"
android:checkable="true"
android:icon="@drawable/ic_cached"
android:title="@string/cached"
app:showAsAction="always" />
<item
... />
<item
... />
</menu>
对于中间项,将其标题设置为“ ”。要使中间图标变大,请参见此处:Change Bottom Bar icon size android
我需要制作一个自定义的 BottomNavigationView,中间有一个更大的图标,没有标题,如下图所示,其他图标大小正常,每个图标下方都有一个标题图标。 我正在使用 android 导航组件库。 如何实现?
我的activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.MainActivity">
<fragment
android:id="@+id/main_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
android:background="#FFF"
app:itemIconTint="@drawable/nav_item_color_state"
app:itemTextColor="@drawable/nav_item_color_state"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/main_navigation_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
和main_navigation_menu
<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">
<item
android:id="@+id/billFragment"
android:checkable="true"
android:icon="@drawable/ic_bill"
android:title="@string/bill"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/paymentsFragment"
android:checkable="true"
android:icon="@drawable/ic_payments"
android:title="@string/payments"
app:showAsAction="always" />
<item
android:id="@+id/cachedFragment"
android:checkable="true"
android:icon="@drawable/ic_cached"
android:title="@string/cached"
app:showAsAction="always" />
<item
... />
<item
... />
</menu>
对于中间项,将其标题设置为“ ”。要使中间图标变大,请参见此处:Change Bottom Bar icon size android