如何使用自定义图像更改复选框的 alpha 值?
我想更改列表视图中复选框的 alpha 值。我可以更改复选框的图像。但不能改变它的alpha值。
layout/list_item.xml
<LinearLayout android:id="@+id/col_1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox android:id="@+id/myCheckBox"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:button="@drawable/bell_checkbox" />
</LinearLayout>
drawable/bell_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bell" android:state_checkable="true" />
<item android:drawable="@drawable/bell" android:state_checkable="false" />
<item android:drawable="@drawable/bell" android:state_checked="true" />
<item android:drawable="@drawable/bell" android:state_checked="false" />
<item android:drawable="@drawable/bell" android:state_enabled="true" />
<item android:drawable="@drawable/bell" android:state_enabled="false" />
<item android:drawable="@drawable/bell" />
</selector>
下面的代码有效,但不是我想要的
AlphaAnimation alpha = new AlphaAnimation (1f, 0.5f); // from 100% visible to 50%
alpha.setDuration (1000); // 1 second, or whatever you want
alpha.setFillAfter(true);
holder.myCheckBox.startAnimation(alpha);
我已经尝试过:
holder.myCheckBox.getBackground().setAlpha(50);
或者
holder.myCheckBox.getBackground().getCurrent().setAlpha(50);
两者都无法更改 alpha 值。
我认为从自定义复选框获取可绘制对象的方式不正确: holder.myCheckBox.getBackground() - 当我将自定义可绘制对象设置为 android:button 时,它无法从 getBackground() 获取可绘制对象。
我怎样才能获得android:button的drawable?
有人能给我一些提示吗?
I want to change the alpha value of the checkbox that in list view. I can change the image for the checkbox. But cannot change the alpha value of it.
layout/list_item.xml
<LinearLayout android:id="@+id/col_1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox android:id="@+id/myCheckBox"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:button="@drawable/bell_checkbox" />
</LinearLayout>
drawable/bell_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bell" android:state_checkable="true" />
<item android:drawable="@drawable/bell" android:state_checkable="false" />
<item android:drawable="@drawable/bell" android:state_checked="true" />
<item android:drawable="@drawable/bell" android:state_checked="false" />
<item android:drawable="@drawable/bell" android:state_enabled="true" />
<item android:drawable="@drawable/bell" android:state_enabled="false" />
<item android:drawable="@drawable/bell" />
</selector>
The code below works, but not what I want
AlphaAnimation alpha = new AlphaAnimation (1f, 0.5f); // from 100% visible to 50%
alpha.setDuration (1000); // 1 second, or whatever you want
alpha.setFillAfter(true);
holder.myCheckBox.startAnimation(alpha);
I have tried:
holder.myCheckBox.getBackground().setAlpha(50);
or
holder.myCheckBox.getBackground().getCurrent().setAlpha(50);
Both cannot change the alpha value.
I think the way that I get the drawable object from my customized checkbox is incorrect:
holder.myCheckBox.getBackground() - It cannot get the drawable object form getBackground() as I set the customized drawable to android:button.
How can I get the drawable of android:button?
Can anyone give me some hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论