How to Implement ColoredShadowImageView Library in Android? - GeeksforGeeks

13 Jan, 2022
Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android OS was developed by Android Inc. which Google bought in 2005. In this article, we are going to implement the ColoredShadowImageView library. While showing an image if we want to add shadow then we do that by creating a file in drawable and then after adding component in that we are able to show the shadow. Here we are going to show shadows in an image using the library.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add this into the build.gradle file
implementation ‘com.github.armcha:ColoredShadowImageView:1.1.0’
You also need to add RenderScript to your app module. Add these lines to the defaultConfig block of your build.gradle.
renderscriptTargetApi YOUR_TARGET_SDK_VERSION
renderscriptSupportModeEnabled true
Step 3: Working with the activity_main.xml file
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
XML
<?xml version="1.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:gravity="center"    tools:context=".ColorShadow">           <!--adding shadowimageview library-->    <io.github.armcha.coloredshadow.ShadowImageView        android:id="@+id/shadowImage"        android:layout_width="250dp"        android:layout_height="250dp"        android:src="@drawable/circle"/>   </LinearLayout>
 
 
Step 4: Working with the MainActivity.java file
 
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file 
 
Java
import androidx.appcompat.app.AppCompatActivity; import android.graphics.drawable.Drawable;import android.os.Bundle;import android.widget.ImageView; import com.bumptech.glide.Glide;import com.bumptech.glide.request.target.ViewTarget; import io.github.armcha.coloredshadow.ShadowImageView; public class ColorShadow extends AppCompatActivity {     ShadowImageView imageViewl;     @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_color_shadow);        imageViewl=findViewById(R.id.shadowImage);                   // showing image using Glide Library        Glide.with(ColorShadow.this).load(R.drawable.circle)                // adding it as placeholder if loading gets null                .placeholder(R.drawable.circle)          .into(imageViewl);    }}
 
 
Output:
 
 
simranarora5sos
Android
Java
Java
Android
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Retrofit with Kotlin Coroutine in Android
Flutter - Custom Bottom Navigation Bar
Android Listview in Java with Example
How to Read Data from SQLite Database in Android?
How to Change the Background Color After Clicking the Button in Android?
Arrays in Java
Split() String method in Java with examples
For-each loop in Java
Arrays.sort() in Java with examples
Initialize an ArrayList in Java