Java Code Examples for android.view.View.setBackground()

The following are Jave code examples for showing how to use setBackground() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SimpleUILauncher   File: DeepShortcutsContainer.java   View Source Code Vote up 6 votes
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LinearLayout.LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.LEFT;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.RIGHT;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
            width, height, !mIsAboveIcon));
    arrowDrawable.getPaint().setColor(Color.WHITE);
    arrowView.setBackground(arrowDrawable);
    arrowView.setElevation(getElevation());
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
Example 2
Project: revolution-irc   File: ThemedEditText.java   View Source Code Vote up 6 votes
public static void setBackgroundActiveColor(View editText, int accentColor) {
    if (editText.getBackground() == null)
        return;
    int normalColor = StyledAttributesHelper.getColor(editText.getContext(),
            R.attr.colorControlNormal, 0);
    int disabledColor = ColorUtils.setAlphaComponent(normalColor, (int) (255.f *
            StyledAttributesHelper.getFloat(editText.getContext(), android.R.attr.disabledAlpha, 1.f)));
    int[][] states = new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    };
    int[] colors = new int[]{
            disabledColor,
            normalColor,
            accentColor
    };
    ColorStateList list = new ColorStateList(states, colors);
    editText.setBackground(new ColorFilterWorkaroundDrawable(editText.getBackground()));
    ViewCompat.setBackgroundTintList(editText, list);
}
 
Example 3
Project: HoldingButton   File: HoldingButtonLayout.java   View Source Code Vote up 6 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    if (mHoldingView == null && mHoldingViewId != NO_ID) {
        mHoldingView = findViewById(mHoldingViewId);
    }

    if (mHoldingView == null) {
        throw new IllegalStateException("Holding view doesn't set. Call setHoldingView before inflate");
    }

    mHoldingCircle = new View(getContext());
    mHoldingCircle.setVisibility(INVISIBLE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mHoldingCircle.setBackground(mHoldingDrawable);
    } else {
        mHoldingCircle.setBackgroundDrawable(mHoldingDrawable);
    }
}
 
Example 4
Project: letv   File: BlurUtils.java   View Source Code Vote up 6 votes
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void blurAdvanced(Context context, Bitmap bkg, View view) {
    if (bkg != null) {
        Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        Paint paint = new Paint();
        paint.setFlags(2);
        canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
        overlay = FastBlur.doBlur(overlay, (int) 12.0f, true);
        if (LetvUtils.getSDKVersion() >= 16) {
            view.setBackground(new BitmapDrawable(context.getResources(), overlay));
        } else {
            view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
        }
    }
}
 
Example 5
Project: android-round-textview   File: DrawableHelper.java   View Source Code Vote up 5 votes
public static void setRoundBackground(View view, Drawable drawable) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 6
Project: GitHub   File: Helper.java   View Source Code Vote up 5 votes
public static void setBackground(View v, Drawable drawable) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    v.setBackground(drawable);
  } else {
    v.setBackgroundDrawable(drawable);
  }
}
 
Example 7
Project: FireFiles   File: ViewCompat.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
   @SuppressWarnings("deprecation")
public static void setBackground(View view, Drawable drawable){
	if(Utils.hasJellyBean()){
		view.setBackground(drawable);
	}
	else{
		view.setBackgroundDrawable(drawable);
	}
}
 
Example 8
Project: easyfilemanager   File: ViewCompat.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
   @SuppressWarnings("deprecation")
public static void setBackground(View view, Drawable drawable){
	if(Utils.hasJellyBean()){
		view.setBackground(drawable);
	}
	else{
		view.setBackgroundDrawable(drawable);
	}
}
 
Example 9
Project: TwitterizedPhotoView   File: TwitterizedImageShowingActivity.java   View Source Code Vote up 5 votes
static void applyViewTransitBackgroundColor(@NonNull View view, int beforeColor,
                                            int afterColor) {
    ColorDrawable[] colors = {new ColorDrawable(beforeColor),
        new ColorDrawable(afterColor)};

    // Transit the background from black
    TransitionDrawable trans = new TransitionDrawable(colors);
    view.setBackground(trans);
    trans.startTransition(BACKGROUND_TRANSITION_DURATION);
}
 
Example 10
Project: OpenVideoCall-Android   File: ViewUtil.java   View Source Code Vote up 5 votes
public static void setBackground(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 11
Project: boohee_v5.6   File: MQUtils.java   View Source Code Vote up 5 votes
public static void setBackground(View v, Drawable bgDrawable) {
    if (VERSION.SDK_INT >= 16) {
        v.setBackground(bgDrawable);
    } else {
        v.setBackgroundDrawable(bgDrawable);
    }
}
 
Example 12
Project: Xndroid   File: DrawableUtils.java   View Source Code Vote up 5 votes
public static void setBackground(@NonNull View view, @Nullable Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        //noinspection deprecation
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 13
Project: QuickActionView   File: QuickActionView.java   View Source Code Vote up 5 votes
public QuickActionViewLayout(Context context, ArrayList<Action> actions, Point centerPoint) {
    super(context);
    mCenterPoint = centerPoint;
    mScrimView = new View(context);
    mScrimView.setBackgroundColor(mScrimColor);
    FrameLayout.LayoutParams scrimParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(mScrimView, scrimParams);
    mIndicatorView = new View(context);
    if (Build.VERSION.SDK_INT >= 16) {
        mIndicatorView.setBackground(mIndicatorDrawable);
    } else {
        mIndicatorView.setBackgroundDrawable(mIndicatorDrawable);
    }
    FrameLayout.LayoutParams indicatorParams = new FrameLayout.LayoutParams(mIndicatorDrawable.getIntrinsicWidth(), mIndicatorDrawable.getIntrinsicHeight());
    addView(mIndicatorView, indicatorParams);
    for (Action action : actions) {
        ConfigHelper helper = new ConfigHelper(action.getConfig(), mConfig);
        ActionView actionView = new ActionView(context, action, helper);
        mActionViews.put(action, actionView);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        addView(actionView, params);
        if (!TextUtils.isEmpty(action.getTitle())) {
            ActionTitleView actionTitleView = new ActionTitleView(context, action, helper);
            actionTitleView.setVisibility(View.GONE);
            mActionTitleViews.put(action, actionTitleView);
            FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            addView(actionTitleView, titleParams);
        }
    }
}
 
Example 14
Project: titanium-android-imagepicker   File: ImagePickerActivity.java   View Source Code Vote up 5 votes
private void drawBackground(View v, int color, boolean isCircle) {
	if (isCircle) {
        GradientDrawable gd = new GradientDrawable();
        gd.setGradientType(GradientDrawable.RADIAL_GRADIENT);
        gd.setColors(new int[]{color, Color.TRANSPARENT });
        gd.setGradientRadius((Defaults.IMAGE_HEIGHT - Defaults.CIRCLE_PADDING)/2);
        v.setBackground(gd);
        
    } else {
        ShapeDrawable oval = new ShapeDrawable (new OvalShape());
        oval.getPaint().setColor(color);
        v.setBackground(oval);
    }
}
 
Example 15
Project: IndicatorSeekBar   File: Indicator.java   View Source Code Vote up 5 votes
/**
 * set the  View to the indicator top container, not influence indicator arrow ;
 * if indicator type is custom , this method will be not work.
 *
 * @param topContentView the view is inside the indicator TOP part, not influence indicator arrow;
 */
public void setIndicatorTopContentView(@NonNull View topContentView) {
    mTopContentView.removeAllViews();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        topContentView.setBackground(getGradientDrawable());
    } else {
        topContentView.setBackgroundDrawable(getGradientDrawable());
    }
    mTopContentView.addView(topContentView);
}
 
Example 16
Project: Watermark   File: OsCompat.java   View Source Code Vote up 5 votes
public static void setBackgroundDrawableCompat(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        //noinspection deprecation
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 17
Project: boohee_v5.6   File: ViewCompat.java   View Source Code Vote up 4 votes
public static void setBackground(View view, Drawable background) {
    view.setBackground(background);
}
 
Example 18
Project: CustomizableCalendar   File: MonthAdapter.java   View Source Code Vote up 4 votes
@Override
public View getView(int position, View view, ViewGroup parent) {
    final CalendarItem currentItem = days.get(position);

    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(layoutResId, null);
    }

    if (viewInteractor != null && viewInteractor.hasImplementedMonthCellBinding()) {
        view = viewInteractor.onMonthCellBindView(view, currentItem);
    } else {
        final TextView dayView = view.findViewById(android.R.id.title);
        final View background = view.findViewById(android.R.id.background);
        final View startSelectionView = view.findViewById(android.R.id.startSelectingText);
        final View endSelectionView = view.findViewById(android.R.id.stopSelectingText);

        startSelectionView.setVisibility(View.GONE);
        endSelectionView.setVisibility(View.GONE);

        if (currentItem == null) {
            background.setBackground(null);
            dayView.setText(null);
        } else if (currentItem.compareTo(calendar.getFirstMonth().withMillisOfDay(0)) < 0) {
            currentItem.setSelectable(false);
            background.setBackground(null);
            dayView.setTextColor(Color.BLACK);
            dayView.setText(currentItem.getDayString());
            dayView.setAlpha(0.6f);
        } else {
            currentItem.setSelectable(true);
            dayView.setAlpha(1f);
            Integer backgroundResource = null;
            if (firstSelectedDay != null) {
                int startSelectedCompared = currentItem.compareTo(firstSelectedDay);
                if (!multipleSelection) {
                    if (startSelectedCompared == 0) {
                        backgroundResource = R.drawable.empty_circle;
                    }
                } else if (startSelectedCompared == 0) {
                    if (lastSelectedDay == null || lastSelectedDay.equals(currentItem.getDateTime())) {
                        backgroundResource = R.drawable.circle;
                    } else {
                        backgroundResource = R.drawable.left_rounded_rectangle;
                        endSelectionView.setVisibility(View.VISIBLE);
                    }
                } else if (startSelectedCompared > 0 && lastSelectedDay != null) {
                    int endSelectedCompared = currentItem.compareTo(lastSelectedDay);
                    if (endSelectedCompared == 0) {
                        backgroundResource = R.drawable.right_rounded_rectangle;
                        startSelectionView.setVisibility(View.VISIBLE);
                    } else if (endSelectedCompared < 0) {
                        backgroundResource = R.drawable.rectangle;
                        startSelectionView.setVisibility(View.VISIBLE);
                        endSelectionView.setVisibility(View.VISIBLE);
                    }
                }
            }

            int color = Color.BLACK;
            if (backgroundResource != null) {
                background.setBackgroundResource(backgroundResource);
                if (multipleSelection) {
                    color = Color.WHITE;
                }
            } else {
                background.setBackground(null);
            }

            dayView.setTextColor(color);
            dayView.setText(currentItem.getDayString());
        }
    }

    return view;
}
 
Example 19
Project: ankihelper   File: ViewUtil.java   View Source Code Vote up 4 votes
public static void setBackground(View v, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        v.setBackground(drawable);
    else
        v.setBackgroundDrawable(drawable);
}
 
Example 20
Project: simple-share-android   File: FabSpeedDial.java   View Source Code Vote up 4 votes
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    LayoutParams layoutParams =
            new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    int coordinatorLayoutOffset = getResources().getDimensionPixelSize(R.dimen.coordinator_layout_offset);
    if (fabGravity == BOTTOM_END || fabGravity == TOP_END) {
        layoutParams.setMargins(0, 0, coordinatorLayoutOffset, 0);
    } else {
        layoutParams.setMargins(coordinatorLayoutOffset, 0, 0, 0);
    }
    menuItemsLayout.setLayoutParams(layoutParams);

    // Needed in order to intercept key events
    setFocusableInTouchMode(true);

    if (useTouchGuard) {
        ViewParent parent = getParent();

        touchGuard = new View(getContext());
        touchGuard.setOnClickListener(this);
        touchGuard.setWillNotDraw(true);
        touchGuard.setVisibility(GONE);

        if (touchGuardDrawable != null) {
            touchGuard.setBackground(touchGuardDrawable);
        }

        if (parent instanceof FrameLayout) {
            FrameLayout frameLayout = (FrameLayout) parent;
            frameLayout.addView(touchGuard, frameLayout.indexOfChild(this));
        } else if (parent instanceof CoordinatorLayout) {
            CoordinatorLayout coordinatorLayout = (CoordinatorLayout) parent;
            coordinatorLayout.addView(touchGuard, coordinatorLayout.indexOfChild(this));
        } else if (parent instanceof RelativeLayout) {
            ((RelativeLayout) parent).addView(
                    touchGuard, ((RelativeLayout) parent).indexOfChild(this),
                    new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT));
        } else {
            Log.d(TAG, "touchGuard requires that the parent of this FabSpeedDialer be a FrameLayout or RelativeLayout");
        }
    }

    setOnClickListener(this);
}