我动态设置一个TextView的背景下,基于一些条件改变目前Android TextView的边框颜色没有变化的背景
textview.setBackgroundResource(R.drawable.attempted_question_border);
OR
textview.setBackgroundResource(R.drawable.skipped_question_background);
XML作为背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/answered_que_bg" >
</solid>
<stroke
android:width="1dp"
android:color="@color/answered_que_bg" >
</stroke>
<corners
android:radius="2dp">
</corners>
</shape>
它设置背景颜色'answers_que_bg'和边框颜色'answers_que_bg'或背景颜色's kipped_question_background'和边框颜色'skipped_question_background'。到现在为止还挺好。现在我需要只更改此文字视图的边框颜色保持背景颜色与原来的相同。我试着用下面的xml改变背景。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/bookmark_color" >
</stroke>
<corners
android:radius="2dp">
</corners>
</shape>
它根据需要更改边框颜色,但背景颜色也丢失。
使用'Drawable#setColorFilter' – pskink
@Ram Mehar Deswal你需要其他的d如果你还改变了textview的背景而不是检查评论代码 –
你试过我的回答@林 –