How to draw profile icon shape in android?


This example demonstrate about How to draw profile icon shape in android.

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:gravity="center"
   android:layout_marginTop="30dp"
   tools:context=".MainActivity">
   <ImageView
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@drawable/background"/>
</LinearLayout>

In the above code, we have taken imageview and added background as background.xml.

Step 3 − Add the following code to drawable/ background.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
   android:width="24dp"
   android:height="24dp"
   android:autoMirrored="true"
   android:viewportWidth="277.58"
   android:viewportHeight="277.58">
   <path
      android:fillColor="#D80027"
      android:pathData="M138.46,164.287c-38.628,0 -69.925,-37.519 -69.925,-83.767C68.535,
                        34.277 99.832,0 138.46,0c38.634,0 69.957,34.277 69.957,80.52C208.417,
                        126.768 177.093,164.287 138.46,164.287zM29.689,277.528c0,0 -14.832,
                        0.979 -21.365,-8.023c-3.53,-4.863 -1.071,-14.718 1.343,-20.217l5.912,
                        -13.473c0,0 16.35,-36.567 34.962,-57.757c11.433,-12.994 25.031,
                        -10.035 33.826,-5.809c5.417,2.6 11.542,10.176 16.018,14.191c6.168,
                        5.532 17.057,11.819 34.859,12.173h10.922c17.791,-0.354 28.68,
                        -6.641 34.843,-12.173c4.471,-4.014 10.427,-11.825 15.795,
                        -14.511c8.072,-4.041 20.358,-6.527 31.492,6.13c18.618,21.191 33.363,
                        58.421 33.363,58.421l6.059,13.212c2.507,5.461 5.075,15.267 1.643,
                        20.195c-6.124,8.811 -19.874,7.642 -19.874,7.642S29.689,277.528 29.689,
                        277.528z" />
</vector>

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run  icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen –

Click here to download the project code

Updated on: 27-Jun-2020

473 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements