我是靠谱客的博主 怕孤独凉面,这篇文章主要介绍动态改变Shape中的颜色,现在分享给大家,希望可以做个参考。

当控件背景是一个Shape时,要想改变其背景色,不能直接使用view.setBackground…
如:


<View
android:id="@+id/v_test"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_below="@id/tv_test"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:background="@drawable/v_background"
/>

v_background.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:height="45dp"
android:width="45dp"/>
<solid android:color="@color/colorPrimaryDark"/>
</shape>

实现代码:


GradientDrawable background = (GradientDrawable) v_test.getBackground();//GradientDrawable是Drawable的子类
background.setColor(Color.RED);

最后

以上就是怕孤独凉面最近收集整理的关于动态改变Shape中的颜色的全部内容,更多相关动态改变Shape中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(139)

评论列表共有 0 条评论

立即
投稿
返回
顶部