ashwin ram kumar
ashwin ram kumar

Reputation: 161

Creating Android XML shape with rectangle and triangle as in figure for Background

I want to create a drawable android XML Background as shown in the Figure could anybody please tell me how to do this. Thank You!! The Picture of Background is enclosed belowenter image description here

Upvotes: 1

Views: 1705

Answers (1)

ankuranurag2
ankuranurag2

Reputation: 2441

You can easily achieve this using Vector Drawables. Just create a file background.xml and paste the following code:

<vector android:height="24dp" android:viewportHeight="472"
    android:viewportWidth="302" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ff008d"
        android:pathData="M0,122.9c0,108.3 0.2,123 1.5,123.5 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.8,-0.9 2.1,-0.5 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0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,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.8,-0.9 2.1,-0.5 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.5,0.5 2,0.4 1.6,-0.4 -0.4,-0.6 -0.2,-1.1 0.3,-1.1 0.8,-0 1.1,-23.5 1.1,-77l0,-77 -151,-0 -151,-0 0,122.9z" android:strokeColor="#00000000"/>
</vector>

You can change the color by changing the color code of fillColor.

Note: You can do the same with any PNG image. Convert the png image to svg HERE. Then in Android Studio go to File>New>Vector Asset>Local File(SVG,PSD)>Finish

Upvotes: 2

Related Questions