以下两张照片是 TextView ,其中包含以下属性:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style"
android:text="select password"
android:textColor="@color/dif_black"/>
并且 button_style.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<layer-list >
<item>
<shape>
<stroke
android:width="2dp"
android:color="#88C425" />
<corners android:radius="20dp" />
</shape>
</item>
第一张照片取自Canvas 2,第二张照片取自三星Galaxy Fame。这是我不希望在 textview 边框(Stroke)内填充黑色的问题。您会在第一张图片中注意到 textview 的背景是透明的。我想在所有Android设备中都这样做是透明的背景。
答案 0 :(得分:15)
您只指定了Shape的笔划,但它需要背景。看来黑色是默认的。
通过添加纯透明背景来更改 button_style.xml 形状:
<shape>
<stroke
android:width="2dp"
android:color="#88C425" />
<corners android:radius="20dp" />
<solid android:color="@android:color/transparent" />
</shape>
答案 1 :(得分:1)
对于简单的TextView,你可以这样做.... (TextView)txtListChild.setBackgroundColor(Color.TRANSPARENT);
但是如果您使用的是ListView,则需要找到每个项目使用的itemview布局并将其设置在那里......像这样的东西
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
convertView.setBackgroundColor(Color.TRANSPARENT);
}
答案 2 :(得分:0)
如果您需要透明色,那么U需要像这样定义
android:background="#ffffffff"
对于Ex
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:text="select password"
android:textColor="#efyfff"/>
或者你可以将背景设置为白色
android:background="@color/white"
更新::
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:text="select password"
android:textColor="#efyfff"/>