Reputation: 59004
I tried to add ripple effect on my TextView used as button which has dark background.
I already tried
android:foreground="?attr/selectableItemBackground"
on TextView android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
on TextView parent becuase Textview has dark background, also tried light theme.Also i can not set TextView background as android:background="attr/selectableItemBackground
because i need some dark background on textview.
Can someone give me understanding, how can i achieve this requirement.
Upvotes: 0
Views: 2091
Reputation: 14636
One can use MaterialButton
like this to have ripple effect on click.
<com.google.android.material.button.MaterialButton
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:paddingHorizontal="@dimen/padding_8dp"
android:text="Clickable Text"
android:textColor="your text color"
app:backgroundTint="@android:color/transparent"
app:rippleColor="ripple effect color" />
Upvotes: 0
Reputation: 21053
The problem is with Dark theme. Ripple color is not being visible on dark . So you should try to use a Custom theme with .
<style name="TextViewTheme" parent="@style/Base.ThemeOverlay.AppCompat.Dark">
<!-- Customize your theme here. -->
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
Add this theme for TextView.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_green_dark"
android:foreground="?android:selectableItemBackground"
android:text="Android"
android:theme="@style/TextViewTheme"
android:clickable="true"
android:textSize="23sp"/>
Upvotes: 1