Start a Project

How to make different shapes in android

In this blog,
I will show you how to make different shapes in android.

Shape

The shape is the XML Element which is defined in XML. and must be the root element.

The file location is :

res/drawable/your_shape.xml
The filename is used as the resource ID.

The values which define the type of shape,

"rectangle": A rectangle that fills the containing View. This is the default shape.

"oval": An oval shape that fits the dimensions of the containing View.

"line": A horizontal line that spans the width of the containing View. This shape requires the  <stroke>   element to define the width of the line.

"ring": A ring shape.

How to create shapes

  1. Circle:
  2. Rectangle:
  3. Ring:
  4. Line:

How to access

In Java: R.drawable.your_shape
In XML: @[package:]drawable/your_shape

Example:

Create the file named circuler_shape.xml

and this XML layout applies to a Textview:

For programmatically:

Source:

https://developer.android.com/

Exit mobile version