Reputation: 1266
I had a tab layout
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:animateLayoutChanges="true"
android:background="@color/background_white" />
For implementing ripple animation I have to change the background to
android:background="?attr/selectableItemBackground"
It enables the ripple animation but the default color is kind of gray and I want my background to be a customized color like white, I also tried
android:background="@color/white"
app:tabBackground="?attr/selectableItemBackground"
But It doesn't appear when the background color is white,
I just don't know what's the reason that it doesn't work on white background?
Upvotes: 3
Views: 2278
Reputation: 1266
finally, I find out how to get a background and selectable item together. first you need to declare two styles in your styles.xml
, like below
<style name="SelectableItemTheme">
<item name="colorControlHighlight">@color/light_gray</item>
</style>
<style name="SelectableItemBackground">
<item name="android:theme">@style/SelectableItemTheme</item>
<item name="android:background">?attr/selectableItemBackground</item>
</style>
And after that you assign it as an style parameter to tab-layout and put the color that you want from it,
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentStart="true"
style="@style/SelectableItemBackground"
android:background="@color/background_login"/>
Upvotes: 7