大佬教程收集整理的这篇文章主要介绍了android – 以编程方式更改图层列表中的形状颜色,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的图层列表:
<@L_674_0@ xmlns:android="http://scheR_95_11845@as.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#000000" /> // CHANGE THIS COLOR </shape> </item> <item android:left="5dp"> <shape android:shape="rectangle"> <solid android:color="@color/bg" /> </shape> </item> </@L_674_0@>
<@L_674_0@ xmlns:android="http://scheR_95_11845@as.android.com/apk/res/android"> <!-- First assign id to the list item--> <item android:id="@+id/your_shape"> <shape android:shape="rectangle"> <solid android:color="#000000" /> </shape> </item> <item android:left="5dp"> <shape android:shape="rectangle"> <solid android:color="@color/bg" /> </shape> </item> </@L_674_0@>
然后通过id获得你的形状.
LayerDrawable shape = (LayerDrawablE) getresources().getDrawable(R.drawable.your_shapE)
你可以通过调用来改变形状的颜色
shape.setColor(Color.black); // changing to black color
编辑
由于getDrawable()已被弃用.使用以下代码行.
LayerDrawable shape = (LayerDrawablE) ContextCompat.getDrawable(YourActivity.this,R.drawable.your_shapE)
以上是大佬教程为你收集整理的android – 以编程方式更改图层列表中的形状颜色全部内容,希望文章能够帮你解决android – 以编程方式更改图层列表中的形状颜色所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。