BottomNavigation风格

时间:2018-02-12 10:50:36

标签: android bottomnavigationview

我有BottomNavigationView

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    app:itemTextColor="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="?android:attr/windowBackground"
    android:foreground="?attr/selectableItemBackground"
    app:itemIconTint="@android:color/white"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />

当我在清单中使用默认styles时,一切正常:

<application
    android:name=".model.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

enter image description here

当我像这样覆盖默认styles

 <style name="base" parent="Theme.AppCompat.Light.NoActionBar" >
    <item name="android:background">@color/grey_dark_bg_md</item>
    <item name="android:textColor">@color/white</item>
</style>

和清单:

    <application
    android:name=".model.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/base">
    <activity
        android

我遇到了问题。非活动底部导航图像剪切

enter image description here

样式有什么问题?

1 个答案:

答案 0 :(得分:0)

您可以如下设置BottomNavigationView的样式:

  1. 在您的styles.xml文件中声明自定义样式。
<style name="BottomNavigation">
    <item name="android:background">@color/indigo</item>
    <item name="itemBackground">@drawable/navigation_bar_item_bg</item>
    <item name="itemIconTint">@color/navigation_bar_txt_color</item>
    <item name="itemTextColor">@color/navigation_bar_txt_color</item>
    <item name="paddingStart">@dimen/bottom_navigation_padding</item>
    <item name="paddingEnd">@dimen/bottom_navigation_padding</item>
</style>
  1. 通过样式属性将此样式应用于您的BottomNavigationView。
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:menu="@menu/bottom_navigation_menu"
    style="@style/BottomNavigation"/>