set View Layer Type Software - Android User Interface

Android examples for User Interface:View Layer

Description

set View Layer Type Software

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 = "";
    private static final int LAYER_TYPE_SOFTWARE = 1;
    public static void setLayerTypeSoftware(View view) {
        setLayerType(view, LAYER_TYPE_SOFTWARE);
    }//from www .j a v a  2 s . co  m
    public static void setLayerType(View view, int type) {
        try {
            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