Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML shape drawable not rendering desired color

I defined a 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?

<?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 :)

like image 525
Kan-Ru Chen Avatar asked Jul 18 '10 11:07

Kan-Ru Chen


People also ask

How do I change the color of a drawable in XML?

Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" . It has the backward compatibility.

What is shape in XML?

The Shape Drawable is an XML file that defines a geometric shape, including colors and gradients. This is used to create a complex shape that can then be attached as the background of a layout or a view on screen.


2 Answers

In drawable I use this xml code to define the border and background:

<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>  
like image 100
supertoonz Avatar answered Oct 04 '22 11:10

supertoonz


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!

like image 42
sonnyd Avatar answered Oct 04 '22 11:10

sonnyd