TheJadav

CustomShapeView in android – Easiest way ever

CustomShapeView is requirnment for almost every application. I have searched most of time how to make custom shape imageview. Recently I found most easy way of doing it, by using below code

CustomShapeView is requirnment for almost every application. I have searched most of time how to make custom shape imageview. Recently I found most easy way of doing it, by using below code

//in xml you need to add attributes to imageview

        android:background="@drawable/bg_circle"
        android:outlineProvider="background"

//Set below line in code file

        imageView.clipToOutline = true

Is it that much easy? Yes, it is.

Note: It is only working for shape drawable (Not vector) and for android >= 21.

You can find full source code here
Here is top rounded corner shape drawable

  
  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#f6eef1" />

    <stroke
        android:width="2dp"
        android:color="#000000" />

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

    <corners android:topLeftRadius="20dp" android:topRightRadius="20dp" />

</shape>
  
  

Share this content:

Share:

More Posts

Introduction to Kotlin: A Versatile and Modern Programming Language

Kotlin, a versatile and modern programming language, offers developers a concise, safe, and interoperable coding experience. With features like null safety, extension functions, and coroutines, Kotlin enhances productivity and readability, making it an attractive choice for Android development and beyond. Whether you’re new to programming or an experienced developer, exploring Kotlin opens up a world of possibilities for building robust and expressive applications.

Mastering the Android Activity Lifecycle: A Comprehensive Guide

The Android Activity Lifecycle is a fundamental concept for Android developers. It defines how an Activity behaves during its lifecycle, from creation to destruction. Understanding the Activity Lifecycle is crucial for managing resources efficiently and delivering a smooth user experience. In this blog post, we’ll briefly introduce the different states an Activity can be in and the main callback methods associated with each state. Let’s dive in and explore this important aspect of Android app development!

Table of Contents

Send Us A Message