jay tandel jay tandel - 2 months ago 19
Android Question

Can we make a triangular background using xml in android studio

I was wondering if we could make a triangular drawable using xml in android studio.

Answer

As in API 21 you can use Vector drawable. so in the drawable folder create triangle.xml file.

like this way.

triangle.xml

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="100dp"
    android:width="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100" >
    <group
        android:name="triableGroup">
        <path
            android:name="triangle"
            android:fillColor="#FF0000"
            android:pathData="m 50,0 l 50,100 -100,0 z" />
    </group>
</vector>

and apply your View background.