gpt4 book ai didi

android - 使用 ActionButton 样式更改图标 ImageView 的波纹颜色

转载 作者:行者123 更新时间:2023-12-04 10:52:11 28 4
gpt4 key购买 nike

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

每个 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>

最佳答案

您可以创建这样的主题:

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

并将这个主题应用到你的 ImageView 中,如下所示:
<ImageView
...
android:theme="@style/RippleColorTheme" />

这应该会改变您在该特定 View 上的涟漪效果的颜色。

关于android - 使用 ActionButton 样式更改图标 ImageView 的波纹颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59424160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com