rei*_*aki 1 android rippledrawable
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item>
<selector>
<item android:state_selected="true">
<layer-list>
<item android:left="-5dp"
android:top="-5dp"
android:right="-5dp">
<shape android:shape="rectangle">
<stroke android:width="3dp"
android:color="@android:color/white"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
</layer-list>
</item>
<item android:state_selected="false">
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
</shape>
</item>
</selector>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
here is my ripple drawable and i want to change the state_selected, solid color.
code i've tried:
RippleDrawable rippleDrawable = (RippleDrawable) textView.getBackground(); // assumes bg is a RippleDrawable
int[][] states = new int[][]{new int[]{android.R.attr.state_selected}};
int[] colors = new int[]{R.color.white};
ColorStateList colorStateList = new ColorStateList(states, colors);
rippleDrawable.setColor(colorStateList);
Run Code Online (Sandbox Code Playgroud)
unfortuantely it doesn't work.. what am I missing and is this possible?
小智 5
您应该为项目添加一个 id 以通过 java/kotlin 访问它们。
检查此背景 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#e0e0e0">
<item android:id="@+id/fab_shape">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp" />
<solid android:color="@color/colorAccent" />
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
为了改变这个的纯色,在constraintLayout背景上,这个drawable XML被应用
val background = constraintLayout.background as RippleDrawable
val bgShape = background.findDrawableByLayerId(R.id.fab_shape) as GradientDrawable
bgShape.color = color
Run Code Online (Sandbox Code Playgroud)
供参考阅读此
| 归档时间: |
|
| 查看次数: |
1661 次 |
| 最近记录: |