Android XML 形状可绘制未呈现所需的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3275333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML shape drawable not rendering desired color
提问by Kan-Ru Chen
I defined a drawable
我定义了一个 drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffffff" />
<size android:width="60dp"
android:height="40dp" />
</shape>
But how to use it in the layout
definition?
但是如何在layout
定义中使用它呢?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/ic_title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
I still see only black background.
我仍然只看到黑色背景。
Edited:
编辑:
It turned out I missed one :
in the drawable
xmlns
declaration. Now this example works in the Gingerbread device :)
结果我:
在drawable
xmlns
声明中漏掉了一个。现在这个例子适用于姜饼设备:)
采纳答案by sonnyd
I had a similar problem and found that if you remove the size definition, it works for some reason.
我有一个类似的问题,发现如果删除尺寸定义,它会出于某种原因起作用。
Remove:
消除:
<size
android:width="60dp"
android:height="40dp" />
from the shape.
从形状。
Let me know if this works!
让我知道这个是否奏效!
回答by supertoonz
In drawable I use this xml code to define the border and background:
在 drawable 中,我使用这个 xml 代码来定义边框和背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="4dp" android:color="#D8FDFB" />
<padding android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
<corners android:radius="4dp" />
<solid android:color="#f0600000"/>
</shape>