我通过添加以下内容来编写具有涟漪效应的android代码:
android:background="?attr/selectableItemBackground"
我需要调整它。我知道如何更改波纹颜色。 但是您认为以下内容甚至可以调整吗?
我知道添加一个可绘制的选择器可以控制更多状态,但是我认为它不能控制持续时间。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_10"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_12"/>
</shape>
</item>
<item android:state_hovered="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_4"/>
</shape>
</item>
</selector>
有可能吗?
答案 0 :(得分:0)
如果您希望继续使用github库,那么可以为您提供帮助
https://github.com/traex/RippleEffect
它具有一个名为app:rv_rippleDuration
的属性,可让您控制持续时间。它还具有许多其他属性。必须尝试一下
编辑
Here是 Sunny 在StackOverflow上给出的一个很好的答案
在/platforms/android-14/data/res/themes.xml
下,您可以找到您要调整的时间段内使用@android:integer/config_mediumAnimTime
的来源。
现在,您可以创建自己的自定义可绘制文件并根据需要更改时间。
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_window_focused="false" android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true" android:drawable="@drawable/list_selector_background_focused" />
<item android:drawable="@color/transparent" />