Example usage for android.view LayoutInflater createView

List of usage examples for android.view LayoutInflater createView

Introduction

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

Prototype

public final View createView(String name, String prefix, AttributeSet attrs)
        throws ClassNotFoundException, InflateException 

Source Link

Document

Low-level function for instantiating a view by name.

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  2s. c o  m*/
        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;
        }
    });
}

From source file:io.github.rockerhieu.emojiconize.EmojiconLayoutInflaterFactory.java

@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    View view = builder.activity.getDelegate().createView(parent, name, context, attrs);
    if (view instanceof EmojiconTextView || view instanceof EmojiconEditText
            || view instanceof EmojiconMultiAutoCompleteTextView) {
        return view;
    }//from w  w  w. j  a  v a  2 s  . com

    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        try {
            view = inflater.createView(name, null, attrs);
        } catch (Exception ignored) {
        }
    }

    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        textView.addTextChangedListener(new EmojiconTextWatcher(textView, builder));
    }
    return view;
}

From source file:com.example.demo_highlights.slidingmenu.activity.SlidingActivity.java

protected void setMenuBackground() {

    //       Log.d(TAG, "??");
    getLayoutInflater().setFactory(new Factory() {

        @Override/*from ww  w.  j a v  a  2  s. co  m*/
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            // TODO Auto-generated method stub
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                //??Android123?????android?packageName?

                try {
                    LayoutInflater f = getLayoutInflater();
                    final View view = f.createView(name, null, attrs); //?

                    new Handler().post(new Runnable() {
                        public void run() {
                            view.setBackgroundResource(R.drawable.bpush_top_bg);
                        }
                    });
                    return view;
                } catch (InflateException e) {
                } catch (ClassNotFoundException e) {
                }
            }

            return null;
        }
    });
}

From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java

/**
 * Unfortunately font-style must be set programmatically //
 * http://stackoverflow/*from www . java  2s  .  com*/
 * .com/questions/10521416/option-menu-default-gray-border-removal <item
 * name="android:panelFullBackground">@color/barbackground</item>
 * 
 */
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    if (this instanceof AboutActivity) {
        return false;
    }

    MenuInflater inflater = getMenuInflater();
    if (this instanceof SignInActivity || this instanceof SignUpActivity
            || this instanceof ResetPasswordActivity) {
        inflater.inflate(R.menu.menusimple, menu);
    } else {
        inflater.inflate(R.menu.menu, menu);
    }

    getLayoutInflater().setFactory(new Factory() {
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater layoutInflater = LayoutInflater.from(context);
                    final View view = layoutInflater.createView(name, null, attrs);

                    new Handler().post(new Runnable() {
                        public void run() {
                            ((TextView) view).setTextColor(Color.WHITE);
                            view.setBackgroundResource(R.drawable.menu_selector);
                        }
                    });
                    return view;
                } catch (Exception e) {
                    Log.w("onCreateOptionsMenu", e.getMessage(), e);
                }
            }
            return null;
        }
    });
    return super.onCreateOptionsMenu(menu);
}