Example usage for android.view ViewGroup setBackgroundDrawable

List of usage examples for android.view ViewGroup setBackgroundDrawable

Introduction

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

Prototype

@Deprecated
public void setBackgroundDrawable(Drawable background) 

Source Link

Usage

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();/*  ww w  .  ja va 2 s .c om*/

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this, 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:mobi.cangol.mobile.navigation.SlidingMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();// w ww  .j  a  v a 2  s . c om

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this.getRootView(), 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

@SuppressWarnings("deprecation")
private void setBackgroundGradient() {

    ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout);
    assert mainLayout != null;
    int h = mainLayout.getHeight();
    int w = mainLayout.getWidth();
    View viewCenterOn = findViewById(R.id.login_frog_logo);
    assert viewCenterOn != null;

    RectShape shape = new RectShape();
    ShapeDrawable mDrawable = new ShapeDrawable(shape);
    int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1);
    int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2);

    RadialGradient shader;//from w w w  .j  a  v  a2s  .  c o  m
    if (w > h) {
        int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2);
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        int remaining = w - left;
        shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f },
                Shader.TileMode.CLAMP);
    } else {
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP);
    }
    mDrawable.setBounds(0, 0, w, h);
    mDrawable.getPaint().setShader(shader);
    mDrawable.getPaint().setDither(true);
    mDrawable.getPaint().setAntiAlias(true);
    mDrawable.setDither(true);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mainLayout.setAnimationCacheEnabled(false);

    mainLayout.setBackgroundDrawable(mDrawable);
}