Example usage for android.view LayoutInflater.Factory LayoutInflater.Factory

List of usage examples for android.view LayoutInflater.Factory LayoutInflater.Factory

Introduction

In this page you can find the example usage for android.view LayoutInflater.Factory LayoutInflater.Factory.

Prototype

LayoutInflater.Factory

Source Link

Usage

From source file:nf.frex.android.FrexActivity.java

static void setMenuBackground(final Activity activity) {
    activity.getLayoutInflater().setFactory(new LayoutInflater.Factory() {
        @Override/*w w w .j  a  v a 2 s  . c  om*/
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater inflater = activity.getLayoutInflater();
                    final View view = inflater.createView(name, null, attrs);
                    new Handler().post(new Runnable() {
                        public void run() {
                            view.setBackgroundColor(Color.argb(127, 0, 0, 0));
                        }
                    });
                    return view;
                } catch (InflateException e) {
                    // :(
                } catch (ClassNotFoundException e) {
                    // :(
                }
            }
            return null;
        }
    });
}