Search code examples
androiddrawshapes

Create triangle with rounded corners


I need to create triangle with rounded corners. Here is my code

<item android:gravity="center">
    <rotate
        android:fromDegrees="45"
        android:pivotX="-40%"
        android:pivotY="87%"
        android:toDegrees="45" >
        <shape android:shape="rectangle" >
            <corners android:radius="2dp"/>
            <solid android:color="#ffffff" >
            </solid>

            <stroke
                android:color="#ffffff" />

        </shape>

    </rotate>
</item>

with my code only one side of triangle is rounded, other two corners not rounded. Please help me to create triangle all corners rounded.


Solution

  • enter image description here

    Create triangle.xml into res/drawable

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:height="50dp"
            android:width="50dp"
            android:viewportHeight="16.0"
            android:viewportWidth="16.0" >
        <path android:fillColor="@color/colorAccent" 
              android:pathData="M11.844,9.04L8.345,5.163c-0.195,-0.217 -0.511,-0.217 -0.705,0l-0.012,0.02L4.136,9.04c-0.195,0.217 -0.195,0.569 0,0.786l0.006,0.005C4.233,9.936 4.358,10 4.499,10h6.983c0.143,0 0.27,-0.068 0.359,-0.176l0.002,0.002C12.039,9.609 12.039,9.257 11.844,9.04z"/>
    </vector>
    

    change color of triangle by changing android:fillColor

    and use @drawable/triangle

    it's easy way.... because simple drawable doesn't have advance features for shape modification.