Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

In this page you can find the example usage for android.view ViewGroup addView.

Prototype

@Override
public void addView(View child, LayoutParams params) 

Source Link

Document

Adds a child view with the specified layout parameters.

Usage

From source file:Main.java

public static void addViewToRoot(Activity act, View v) {
    ViewGroup root = (FrameLayout) act.findViewById(android.R.id.content);
    root = (ViewGroup) root.getChildAt(0);
    ViewGroup.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    root.addView(v, params);
}

From source file:Main.java

private static void setupStatusBarView(Activity activity, ViewGroup contentLayout, int color) {

    View mStatusBarView = null;/*from w ww .j  a va2  s.c  o m*/

    View statusBarView = new View(activity);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getStatusBarHeight(activity));
    contentLayout.addView(statusBarView, lp);

    mStatusBarView = statusBarView;

    mStatusBarView.setBackgroundColor(color);
}

From source file:Main.java

public static void swapViewGroupChildren(ViewGroup viewGroup, View firstView, View secondView) {
    int firstIndex = viewGroup.indexOfChild(firstView);
    int secondIndex = viewGroup.indexOfChild(secondView);
    if (firstIndex < secondIndex) {
        viewGroup.removeViewAt(secondIndex);
        viewGroup.removeViewAt(firstIndex);
        viewGroup.addView(secondView, firstIndex);
        viewGroup.addView(firstView, secondIndex);
    } else {//w w w  .ja v a  2s  . c  o m
        viewGroup.removeViewAt(firstIndex);
        viewGroup.removeViewAt(secondIndex);
        viewGroup.addView(firstView, secondIndex);
        viewGroup.addView(secondView, firstIndex);
    }
}

From source file:Main.java

/**
 *
 * @param act//from   w w w. ja  v  a 2 s  . co m
 * @return
 */
public static RelativeLayout getContainerView(Activity act) {
    // create a new relative layout
    RelativeLayout rl = new RelativeLayout(act);

    // fint the root view of the activity
    ViewGroup fl = (ViewGroup) act.findViewById(android.R.id.content);
    fl = (ViewGroup) fl.getChildAt(0);
    Log.d("DEBUG", "w: " + fl.getWidth() + "h: " + fl.getHeight());

    // Params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
    //        new FrameLayout.LayoutParams(-1, -1);
    // add to the root view of the activity
    fl.addView(rl, params);

    return rl;
}

From source file:com.userhook.UserHook.java

public static void displayPrompt(String message, UHMessageMetaButton button1, UHMessageMetaButton button2) {

    UHMessageMeta meta = new UHMessageMeta();
    meta.setBody(message);//from   ww w .  ja v  a  2s  .c  om

    if (button1 != null && button2 != null) {
        meta.setDisplayType(UHMessageMeta.TYPE_TWO_BUTTONS);
    } else if (button1 != null) {
        meta.setDisplayType(UHMessageMeta.TYPE_ONE_BUTTON);
    } else {
        meta.setDisplayType(UHMessageMeta.TYPE_NO_BUTTONS);
    }

    meta.setButton1(button1);
    meta.setButton2(button2);

    // add view to screen
    UHMessageView view = new UHMessageView(activityLifecycle.getCurrentActivity(), meta);
    ViewGroup rootView = (ViewGroup) activityLifecycle.getCurrentActivity().findViewById(android.R.id.content);
    rootView.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    view.showDialog();
}

From source file:com.marc.marclibs.utils.StatusBarCompat.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static View compat(Activity activity, int statusColor) {
    int color = ContextCompat.getColor(activity, R.color.primary_light);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (statusColor != INVALID_VAL) {
            color = statusColor;//from   w  ww. ja v a2 s .  c  o  m
        }
        activity.getWindow().setStatusBarColor(color);
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (statusColor != INVALID_VAL) {
            color = statusColor;
        }
        View statusBarView = contentView.getChildAt(0);
        if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
            statusBarView.setBackgroundColor(color);
            return statusBarView;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight(activity));
        statusBarView.setBackgroundColor(color);
        contentView.addView(statusBarView, lp);
        return statusBarView;
    }
    return null;

}

From source file:com.yunyou.yike.utils.StatusBarCompat.java

public static View compat(Activity activity, int statusColor) {
    int color = ContextCompat.getColor(activity, R.color.colorPrimaryDark);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (statusColor != INVALID_VAL) {
            color = statusColor;/* ww  w.  j  a v a2s  .com*/
        }
        activity.getWindow().setStatusBarColor(color);
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (statusColor != INVALID_VAL) {
            color = statusColor;
        }
        View statusBarView = contentView.getChildAt(0);
        if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
            statusBarView.setBackgroundColor(color);
            return statusBarView;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight(activity));
        statusBarView.setBackgroundColor(color);
        contentView.addView(statusBarView, lp);
        return statusBarView;
    }
    return null;

}

From source file:com.bs.hjsyxt.utils.StatusBarCompat.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static View compat(Activity activity, int statusColor) {
    int color = ContextCompat.getColor(activity, R.color.colorPrimaryDark);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (statusColor != INVALID_VAL) {
            color = statusColor;/*from   w  w  w  .  ja  v a  2  s  .  com*/
        }
        activity.getWindow().setStatusBarColor(color);
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (statusColor != INVALID_VAL) {
            color = statusColor;
        }
        View statusBarView = contentView.getChildAt(0);
        if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
            statusBarView.setBackgroundColor(color);
            return statusBarView;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight(activity));
        statusBarView.setBackgroundColor(color);
        contentView.addView(statusBarView, lp);
        return statusBarView;
    }
    return null;

}

From source file:com.yoyiyi.bookreadercopy.utils.StatusBarCompat.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP) //21
public static View compat(Activity activity, int statusColor) {
    int color = ContextCompat.getColor(activity, R.color.colorPrimaryDark);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (statusColor != INVALID_VAL) {
            color = statusColor;//from  ww  w. java  2s . com
        }
        activity.getWindow().setStatusBarColor(color);
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (statusColor != INVALID_VAL) {
            color = statusColor;
        }
        View statusBarView = contentView.getChildAt(0);
        if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
            statusBarView.setBackgroundColor(color);
            return statusBarView;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight(activity));
        statusBarView.setBackgroundColor(color);
        contentView.addView(statusBarView, lp);
        return statusBarView;
    }
    return null;

}

From source file:com.linkbubble.util.Util.java

static public void replaceViewAtPosition(View viewToReplace, View replaceWith) {
    ViewGroup parent = (ViewGroup) viewToReplace.getParent();
    int index = parent.indexOfChild(viewToReplace);
    parent.removeView(viewToReplace);//from  w w  w  .  j  a  v a 2 s. c  o  m
    parent.addView(replaceWith, index);
}