如何动态更改笔触颜色? [英] How to change stroke color dynamically?
本文介绍了如何动态更改笔触颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(抱歉,我的语言是法语)
(Sorry for my language, I'm french)
我需要更改Shape的stroke color
.
我在此处中描述了同样的问题.
当EditText不正确时,我需要更改纯色.
I need to change the stroke color
of a Shape.
I've the same problem described here.
I need to change solid color when the EditText is not correct.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
<stroke android:width="2px" android:color="#CCCCCC"/>
</shape>
答案:
GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
myGrad.setColor(Color.BLACK);
答案中的问题是,我不理解矩形项. 如果我将其替换为EditText,它将应用于背景,而不是纯色背景.
Problem in the answer is, I don't understand the rectangle item. If I replace it by the EditText, it is applied to the background, not the solid background.
谢谢.
我的坏人,我想更改描边的颜色,而不是纯色.
EDIT : My Bad, i want to change the Stroke color, not solid.
推荐答案
GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
myGrad.setStroke(2, Color.RED);
这篇关于如何动态更改笔触颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文