【问题标题】:Change ripple color of icon imageview using ActionButton styling使用 ActionButton 样式更改图标图像视图的波纹颜色
【发布时间】:2019-12-20 21:43:21
【问题描述】:

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

每个 ImageView 都有style="@style/Widget.AppCompat.ActionButton" 来实现涟漪效果。

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

当前效果示例:

布局文件:

<?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>

【问题讨论】:

  • 我发布了一个解决方案,但我不确定 style="@style/Widget.AppCompat.ActionButton" 是否会在您的图像视图中添加波纹。如果没有,或者我的回答没有帮助,我将使用自定义涟漪实现对其进行编辑。

标签: android android-layout


【解决方案1】:

你可以像这样创建一个主题:

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

并将这个主题应用到您的图像视图中,如下所示:

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

这应该会改变该特定视图上的涟漪效果的颜色。

【讨论】:

  • 我不得不在我的风格中使用parent="Widget.AppCompat.ActionButton"。似乎不适用于parent="AppTheme.NoActionBar"。如果您更新答案以反映这一点,我会将其标记为已接受。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-15
  • 1970-01-01
  • 2011-01-29
  • 2013-03-29
  • 1970-01-01
  • 2014-01-13
相关资源
最近更新 更多