我试图在用作深色背景的按钮的文本视图上添加涟漪效果。
我已经试过了
- 文本视图上的
android:foreground="?attr/selectableItemBackground"
-
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
在文本视图父级上,因为文本视图具有深色背景,也尝试了浅色主题。
此外,我无法将文本视图背景设置为android:background="attr/selectableItemBackground
因为我需要在文本视图上设置一些深色背景。
有人可以给我理解,我怎样才能达到这个要求。
问题出在深色主题上。 波纹颜色在深色 .因此,您应该尝试将自定义主题与 .
<style name="TextViewTheme" parent="@style/Base.ThemeOverlay.AppCompat.Dark">
<!-- Customize your theme here. -->
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
为文本视图添加此主题。
<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"/>
可以使用
这样的MaterialButton
对点击产生连锁反应。
<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" />