set View Layer Type - Android User Interface

Android examples for User Interface:View Layer

Description

set View Layer Type

Demo Code


import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.inputmethod.InputMethodManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main{
    private static final String TAG = "";
    public static void setLayerType(View view, int type) {
        try {/*w w  w. j  a va 2s  . com*/
            Class[] paramTypes = new Class[1];
            paramTypes[0] = Integer.TYPE;
            Method setLayerTypeMethod = view.getClass().getMethod(
                    "setLayerType", paramTypes);
            setLayerTypeMethod.invoke(view, type);
            Log.d(TAG, "setLayerType successfully called");
        } catch (NoSuchMethodException e) {
            // method does not exist in this api level
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials