使用ActionButton样式更改图标imageview的波纹颜色

时间:2019-12-20 11:02:37

标签: android android-layout

我正在尝试将波纹效果的颜色更改为白色(而不是默认的深灰色)。

每个ImageView都有style="@style/Widget.AppCompat.ActionButton"来达到波纹效果。

我尝试应用tint / backgroundtint /在styles.xml中创建自定义样式-没有一个会影响波纹的颜色。

当前效果的示例:

Action button example of ripple effect

布局文件:

<?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/item_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#333333"
        >
        <ImageView
            android:id="@+id/info_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_info_outline_white_24dp"
            style="@style/Widget.AppCompat.ActionButton"
            android:clickable="true"
            android:focusable="true"
            app:layout_constraintVertical_chainStyle="spread"
            app:layout_constraintRight_toLeftOf="@+id/share_btn"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <ImageView
            android:id="@+id/share_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_share_white_24dp"
            style="@style/Widget.AppCompat.ActionButton"
            android:clickable="true"
            android:focusable="true"
            app:layout_constraintVertical_chainStyle="spread"
            app:layout_constraintStart_toEndOf="parent"
            app:layout_constraintEnd_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <ImageView
            android:id="@+id/delete_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_delete_white_24dp"
            style="@style/Widget.AppCompat.ActionButton"
            android:clickable="true"
            android:focusable="true"
            app:layout_constraintVertical_chainStyle="spread"
            app:layout_constraintLeft_toRightOf="@id/share_btn"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:2)

您可以创建这样的主题:

<style name="RippleColorTheme" parent="Widget.AppCompat.ActionButton">
    <item name="colorControlHighlight">@color/yourRippleColor</item>
</style>

像这样将这个主题应用于您的图像视图:

<ImageView
    ...
    android:theme="@style/RippleColorTheme" />

这应该会更改特定视图上波纹效果的颜色。