1 / 9

Create Gradient and Oval Shapes in Android XML Drawable Files

Learn how to create custom shapes in Android using XML drawable resources. This guide will walk you through the steps to define gradient shapes and oval shapes. Start by creating a new XML file in the drawable directory, define a gradient with specified start and end colors, and then apply this drawable as a background in your layout. Additionally, discover how to create an oval shape and set it as the background of a TextView. Enhance your app's UI with these simple yet effective design elements!

teige
Télécharger la présentation

Create Gradient and Oval Shapes in Android XML Drawable Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android: Shapes

  2. Right click on res/drawable select New/Android XML

  3. Supply a filename (small letters) Choose shape as the root element. Click Finish.

  4. Enter a gradient element, supply its startColor and endColor attributes. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:startColor="#cccccc" android:endColor="#333333" /> </shape>

  5. In your layout add a background attribute and set its value to the xml file you just placed in drawable

  6. The result in Graphical Layout mode.

  7. Add another Android XML file to drawable <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#3399ff" /> </shape>

  8. Set the TextView’s android:background attribute to &srawable/my_circle

  9. Result of setting TextView’s background to shape (oval)

More Related