小编use*_*731的帖子

如何动态改变笔触颜色?

(对不起我的语言,我是法国人)

我需要改变stroke color一个Shape.我有同样的问题在这里描述.当EditText不正确时,我需要更改纯色.

<?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>
Run Code Online (Sandbox Code Playgroud)

答案 :

GradientDrawable myGrad = (GradientDrawable)rectangle.getBackground();
myGrad.setColor(Color.BLACK);
Run Code Online (Sandbox Code Playgroud)

答案中的问题是,我不明白矩形项.如果我用EditText替换它,它将应用于背景,而不是纯色背景.

提前致谢.

编辑:我的坏,我想改变笔画颜色,而不是固体.

android shape android-studio

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-studio ×1

shape ×1