Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a shape's background in xml?

I just created a red circle using android shapes:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:innerRadiusRatio="4"     android:shape="ring"     android:thicknessRatio="9"     android:useLevel="false" >       <solid android:color="#FF0000" />      <size         android:height="48dip"         android:width="48dip" />  </shape> 

This is really cool, but I cannot set the background color of the circle to my color. I tried android:background="#FFFFFF" but it always appear to be black in my layout. How can I set the background of the above shape?

like image 915
Waza_Be Avatar asked Feb 13 '12 16:02

Waza_Be


People also ask

How do you make a rounded corner in a XML file?

This round_corners.xml can be used to make a Circle, rounded corner rectangle, and and oval button. A circle, since the width and height of this view is 60dp, and the radius defined in the round_corners shape is half the length of the view’s width and height, so it makes this view a circle.

What is the background-image property in CSS?

The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. This example shows a bad combination of text and background image. The text is hardly readable: Note: When using a background image, use an image that does not disturb the text.

What is background color in CSS example?

CSS background-color. The background-color property specifies the background color of an element. Example. The background color of a page is set like this: body { background-color: lightblue; } Try it Yourself » With CSS, a color is most often specified ...

How to tile a background image into a pattern using SVG?

The background-repeat property allows you to tile the background image into a pattern. SVGs are a transparent image format and if the SVG elements do not cover the entire viewBox, the background color will be visible behind your SVG. The background origin determines the boundary of the background’s container.


1 Answers

I think a layer-list might help you:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >      <item>         <shape android:shape="rectangle" >             <solid android:color="#ffffff" />         </shape>     </item>     <item>         <shape             android:innerRadiusRatio="4"             android:shape="ring"             android:thicknessRatio="9"             android:useLevel="false" >             <solid android:color="#FF0000" />             <size                 android:height="48dip"                 android:width="48dip" />         </shape>     </item>  </layer-list> 
like image 164
user Avatar answered Oct 10 '22 04:10

user