Android Create EmbossMaskFilter Example Tutorial

How to create textview inner shadow effect like Photoshop blinding options in android application.

Android EmbossMaskFilter is used to create different types of textview shadow effects and most of them is inner shadow effect like we have designed with Photoshop. There are some functions available with this class that can be used with paint class. So here we are using the simplest method to convert TextView text into EmbossMaskFilter text, So here is the complete step by step tutorial for Android Create EmbossMaskFilter Example Tutorial.

android-project-download-code-button

Android Create EmbossMaskFilter Example Tutorial.

Code for MainActivity.java file.

 package com.embossmaskfilter_android_examples.com;

import android.app.Activity;
import android.graphics.EmbossMaskFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

 TextView EmbossMaskFilterText;
 EmbossMaskFilter embossmaskfilter;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 EmbossMaskFilterText = (TextView)findViewById(R.id.textView1);
 
 embossmaskfilter = new EmbossMaskFilter( new float[]
 {1,5,1},//array of 3 scalars [x, y, z] specifying the direction of the light source.
 0.6f,//0-1 amount of ambient light.
 11,//coefficient for specular highlights.
 7.2f//amount to blur before applying lighting.
 );
 
 EmbossMaskFilterText.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
 
 EmbossMaskFilterText.getPaint().setMaskFilter(embossmaskfilter);
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.embossmaskfilter_android_examples.com.MainActivity" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="SAMPLE TEXT"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:textColor="#00f0ba"
 android:textSize="40dp" />

</RelativeLayout>

Screenshot:

Android Create EmbossMaskFilter Example Tutorial

Click here to download Android Create EmbossMaskFilter Example Tutorial project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *