Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Shape Line

Tags:

I have the following code:

   <shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="line">    <stroke android:width="1dp"/>    <size android:height="1dp" />    <solid  android:color="#FFF"/>    </shape>      <LinearLayout      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:background ="@drawable/line"/> 

I have two questions:

  1. Why the line is black instead white? I have tried putting it inside a ImageView but the result is the same.
  2. How can i set the opacity of the shape?
like image 561
Gerardo Avatar asked May 03 '10 11:05

Gerardo


People also ask

What is an android shape?

The <shape> element is where the shape of your drawable is defined and all its nested elements are defined. The android:shape attribute can hold four values: rectangle , oval , ring , or line . If you do not specify a value, it will be a rectangle by default.

What is stroke in shape android?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.

What is drawable shape android?

A ShapeDrawable takes a Shape object and manages its presence on the screen. If no Shape is given, then the ShapeDrawable will default to a RectShape . This object can be defined in an XML file with the <shape> element.

How do I open a drawable file?

Inside Android Studio go to File -> Settings -> Plugins -> Browse repositories. Search Android Drawable Preview.


1 Answers

1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.

2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.

like image 67
Dan Lew Avatar answered Sep 21 '22 05:09

Dan Lew