Android - Material Theme - Color Change. Asset for active tab

Here is my custom theme file:

<style name="MyMaterial" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#4CAF50</item>
    <item name="colorPrimaryDark">#4CAF50</item>
    <item name="colorAccent">#FFFFFF</item>
</style>

      

The problem is, I only want #FFFFFF to highlight the active tab (like yellow in this ), but not other controls like the checkbox is activated. What is the best / correct way to do this?

Side questions: - The tab has vertical dividers by default. How to remove them like in the picture above? - How do I add shadow under the tabs like the image above?

Thank.

+3


source to share


1 answer


By default TabLayout

, the Android Design Support Library part displays the color of the tab indicator from colorAccent

, but you can also use app:tabIndicatorColor

to set a different color, especially to TabLayout

(and not include yellow as the accent color in your theme):

<android.support.design.widget.TabLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:tabIndicatorColor="#FFFFFF" />

      



TabLayout does not have any separator lines, as per the [material design spec][3]. The shadow is added via elevation - if you include your

TabLayout` in AppBarLayout will get you promoted on Android 5.0 and above devices.

+1


source







All Articles