Add bottom nav icon and text color styles and demos.

Add the two baseline bottom nav color styles:

1. default baseline: white background, colorPrimary for activated item text/icon colors, and percentages of black and for non-activated text/icon colors
2. colored baseline: colorPrimary background and percentages of white for icon/text colors

PiperOrigin-RevId: 179937660
This commit is contained in:
afohrman 2017-12-22 13:11:29 -05:00 committed by Daniel Nizri
parent b7fb904d18
commit 21223662b9
4 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2017 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.0" android:color="@android:color/white" android:state_checked="true" android:state_enabled="true"/>
<item android:alpha="0.54" android:color="@android:color/white" android:state_enabled="true"/>
<!-- 38% of 0.54 -->
<item android:alpha="0.21" android:color="@android:color/white"/>
</selector>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2017 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="1.0" android:color="?attr/colorPrimary" android:state_checked="true" android:state_enabled="true"/>
<item android:alpha="0.54" android:color="#000000" android:state_enabled="true"/>
<!-- 38% of 0.54 -->
<item android:alpha="0.21" android:color="#000000"/>
</selector>

View File

@ -616,7 +616,9 @@
<enum name="unlabeled" value="2"/>
</attr>
<attr name="itemBackground"/>
<!-- The tint to apply to the navigation items' icons. -->
<attr name="itemIconTint"/>
<!-- The color to apply to the navigation items' text. -->
<attr name="itemTextColor"/>
<!-- Whether the items should translate horizontally when in shifting mode. -->
<attr name="itemHorizontalTranslation" format="boolean"/>

View File

@ -51,14 +51,26 @@
<item name="itemHorizontalTranslation">true</item>
</style>
<!-- Default style for BottomNavigationViews.
Use the default style to get the default bottom navigation bar with a white background and
colorPrimary for the icon and text colors. -->
<style name="Widget.MaterialComponents.BottomNavigationView" parent="Widget.Design.BottomNavigationView">
<item name="android:background">?attr/colorPrimary</item>
<item name="itemIconTint">?attr/colorAccent</item>
<item name="android:background">@android:color/white</item>
<item name="itemHorizontalTranslation">false</item>
<item name="itemTextColor">?attr/colorAccent</item>
<item name="itemIconTint">@color/mtrl_bottom_nav_item_tint</item>
<item name="itemTextColor">@color/mtrl_bottom_nav_item_tint</item>
<item name="shiftingMode">off</item>
</style>
<!-- Colored style for Bottom NavigationViews.
Use the colored style to get a bottom navigation bar with a colorPrimary background and
percentages of white for the icon and text colors. -->
<style name="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="android:background">?attr/colorPrimary</item>
<item name="itemIconTint">@color/mtrl_bottom_nav_colored_item_tint</item>
<item name="itemTextColor">@color/mtrl_bottom_nav_colored_item_tint</item>
</style>
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabMaxWidth">@dimen/design_tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>