Java Code Examples for android.support.v4.view.ViewCompat#setBackground()

The following examples show how to use android.support.v4.view.ViewCompat#setBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingMessageViewHolder.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void toggleEmojiView(boolean value){
    if (value){
        if (bubble != null) {
            ViewCompat.setBackground(bubble, null);

            bubble.setPadding(0, 0, 0, 0);
        }

        if (text != null){
            text.setTextSize(EMOJI_VIEW_TEXT_SIZE);
        }
    }else {
        if (bubble != null) {
            ViewCompat.setBackground(bubble, defaultBackgroundDrawable);

            bubble.setPadding(defaultPaddingLeft, defaultPaddingTop, defaultPaddingRight, defaultPaddingBottom);
        }

        if (text != null){
            text.setTextSize(TypedValue.COMPLEX_UNIT_PX, defaultTextSizePx);
        }
    }
}
 
Example 2
Source File: ShadowView.java    From YCCardView with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化画笔操作
 */
private void initPaint() {
    bgPaint.setColor(backgroundColor);
    bgPaint.setAntiAlias(true);
    bgPaint.setStyle(Paint.Style.FILL);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    setWillNotDraw(false);
    ViewCompat.setBackground(this, null);
}
 
Example 3
Source File: FullScreenDialogFragment.java    From FullScreenDialog with Apache License 2.0 5 votes vote down vote up
private void setThemeBackground(View view) {
    TypedValue a = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        view.setBackgroundColor(a.data);
    } else {
        try {
            Drawable d = ResourcesCompat.getDrawable(getActivity().getResources(), a.resourceId, getActivity().getTheme());
            ViewCompat.setBackground(view, d);
        } catch (Resources.NotFoundException ignore) {
        }
    }
}
 
Example 4
Source File: SwipeMenuView.java    From SwipeRecyclerView-master with Apache License 2.0 5 votes vote down vote up
public void createMenu(SwipeMenu swipeMenu, SwipeSwitch swipeSwitch,
                       SwipeMenuItemClickListener swipeMenuItemClickListener,
                       @SwipeMenuRecyclerView.DirectionMode int direction) {
    removeAllViews();

    this.mSwipeSwitch = swipeSwitch;
    this.mItemClickListener = swipeMenuItemClickListener;
    this.mDirection = direction;

    List<SwipeMenuItem> items = swipeMenu.getMenuItems();
    for (int i = 0; i < items.size(); i++) {
        SwipeMenuItem item = items.get(i);

        LayoutParams params = new LayoutParams(item.getWidth(), item.getHeight());
        params.weight = item.getWeight();
        LinearLayout parent = new LinearLayout(getContext());
        parent.setId(i);
        parent.setGravity(Gravity.CENTER);
        parent.setOrientation(VERTICAL);
        parent.setLayoutParams(params);
        ViewCompat.setBackground(parent, item.getBackground());
        parent.setOnClickListener(this);
        addView(parent);

        SwipeMenuBridge menuBridge = new SwipeMenuBridge(mDirection, i, mSwipeSwitch, parent);
        parent.setTag(menuBridge);

        if (item.getImage() != null) {
            ImageView iv = createIcon(item);
            menuBridge.mImageView = iv;
            parent.addView(iv);
        }

        if (!TextUtils.isEmpty(item.getText())) {
            TextView tv = createTitle(item);
            menuBridge.mTextView = tv;
            parent.addView(tv);
        }
    }
}
 
Example 5
Source File: InstaTag.java    From InstaTag with Apache License 2.0 5 votes vote down vote up
private void addTag(Tag tag) {
    LayoutInflater layoutInflater = LayoutInflater.from(mContext);

    float x = getXCoOrdForTag(tag.getX_co_ord());
    float y = getYCoOrdForTag(tag.getY_co_ord());

    final View tagView = layoutInflater.
            inflate(R.layout.view_for_tag, mRoot, false);
    final TextView tagTextView = tagView.findViewById(R.id.tag_text_view);

    final LinearLayout carrotTopContainer =
            tagView.findViewById(R.id.carrot_top);

    final LinearLayout textContainer =
            tagView.findViewById(R.id.tag_text_container);

    if (mTagTextDrawable != null) {
        ViewCompat.setBackground(textContainer, mTagTextDrawable);
    }
    if (mCarrotTopDrawable != null) {
        ViewCompat.setBackground(carrotTopContainer, mCarrotTopDrawable);
    }

    tagTextView.setText(tag.getUnique_tag_id());
    setColorForTag(tagView);

    tagView.setX(x);
    tagView.setY(y);

    mTagList.add(tagView);
    mRoot.addView(tagView);
}
 
Example 6
Source File: ShadowDrawable.java    From ShadowDrawable with MIT License 5 votes vote down vote up
/**
 * 为指定View添加阴影
 * @param view 目标View
 * @param shapeRadius View的圆角
 * @param shadowColor 阴影的颜色
 * @param shadowRadius 阴影的宽度
 * @param offsetX 阴影水平方向的偏移量
 * @param offsetY 阴影垂直方向的偏移量
 */
public static void setShadowDrawable(View view, int shapeRadius, int shadowColor, int shadowRadius, int offsetX, int offsetY) {
	ShadowDrawable drawable = new ShadowDrawable.Builder()
			.setShapeRadius(shapeRadius)
			.setShadowColor(shadowColor)
			.setShadowRadius(shadowRadius)
			.setOffsetX(offsetX)
			.setOffsetY(offsetY)
			.builder();
	view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
	ViewCompat.setBackground(view, drawable);
}
 
Example 7
Source File: MessageHolders.java    From ChatKit with Apache License 2.0 5 votes vote down vote up
@Override
public final void applyStyle(MessagesListStyle style) {
    super.applyStyle(style);
    if (time != null) {
        time.setTextColor(style.getOutcomingImageTimeTextColor());
        time.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getOutcomingImageTimeTextSize());
        time.setTypeface(time.getTypeface(), style.getOutcomingImageTimeTextStyle());
    }

    if (imageOverlay != null) {
        ViewCompat.setBackground(imageOverlay, style.getOutcomingImageOverlayDrawable());
    }
}
 
Example 8
Source File: SwipeMenuView.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
public void createMenu(RecyclerView.ViewHolder viewHolder, SwipeMenu swipeMenu, Controller controller,
    int direction, OnItemMenuClickListener itemClickListener) {
    removeAllViews();

    this.mViewHolder = viewHolder;
    this.mItemClickListener = itemClickListener;

    List<SwipeMenuItem> items = swipeMenu.getMenuItems();
    for (int i = 0; i < items.size(); i++) {
        SwipeMenuItem item = items.get(i);

        LayoutParams params = new LayoutParams(item.getWidth(), item.getHeight());
        params.weight = item.getWeight();
        LinearLayout parent = new LinearLayout(getContext());
        parent.setId(i);
        parent.setGravity(Gravity.CENTER);
        parent.setOrientation(VERTICAL);
        parent.setLayoutParams(params);
        ViewCompat.setBackground(parent, item.getBackground());
        parent.setOnClickListener(this);
        addView(parent);

        SwipeMenuBridge menuBridge = new SwipeMenuBridge(controller, direction, i);
        parent.setTag(menuBridge);

        if (item.getImage() != null) {
            ImageView iv = createIcon(item);
            parent.addView(iv);
        }

        if (!TextUtils.isEmpty(item.getText())) {
            TextView tv = createTitle(item);
            parent.addView(tv);
        }
    }
}
 
Example 9
Source File: AndroidBinder.java    From data-mediator with Apache License 2.0 4 votes vote down vote up
@Override
protected void apply(Property prop, View view, Object newValue) {
    ViewCompat.setBackground(view, (Drawable) newValue);
}
 
Example 10
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setShapeBg(View view, int shape, int bgColor, int radius) {
	ViewCompat.setBackground(view, getDrawable(shape, bgColor, radius));
}
 
Example 11
Source File: MinimalKSnack.java    From KSnack with Apache License 2.0 4 votes vote down vote up
public MinimalKSnack setBackgrounDrawable(@NonNull @DrawableRes int drawableInt){
    // Set drawable to view.
    ViewCompat.setBackground(lnrSnack, ContextCompat.getDrawable(lnrSnack.getContext(), drawableInt));

    return this;
}
 
Example 12
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setShapeBg(View view, int shape, int bgColor, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(shape, bgColor, radius));
}
 
Example 13
Source File: BottomNavigationItemView.java    From MiPushFramework with GNU General Public License v3.0 4 votes vote down vote up
public void setItemBackground(int background) {
    Drawable backgroundDrawable = background == 0
            ? null : ContextCompat.getDrawable(getContext(), background);
    ViewCompat.setBackground(this, backgroundDrawable);
}
 
Example 14
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, GradientDrawable.Orientation[] orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, GradientDrawable.RECTANGLE, orientation, bgColor,
			borderColor, borderWidth, radius));
}
 
Example 15
Source File: MessageInput.java    From ChatKit with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    init(context);
    MessageInputStyle style = MessageInputStyle.parse(context, attrs);

    this.messageInput.setMaxLines(style.getInputMaxLines());
    this.messageInput.setHint(style.getInputHint());
    this.messageInput.setText(style.getInputText());
    this.messageInput.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getInputTextSize());
    this.messageInput.setTextColor(style.getInputTextColor());
    this.messageInput.setHintTextColor(style.getInputHintColor());
    ViewCompat.setBackground(this.messageInput, style.getInputBackground());
    setCursor(style.getInputCursorDrawable());

    this.attachmentButton.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE);
    this.attachmentButton.setImageDrawable(style.getAttachmentButtonIcon());
    this.attachmentButton.getLayoutParams().width = style.getAttachmentButtonWidth();
    this.attachmentButton.getLayoutParams().height = style.getAttachmentButtonHeight();
    ViewCompat.setBackground(this.attachmentButton, style.getAttachmentButtonBackground());

    this.attachmentButtonSpace.setVisibility(style.showAttachmentButton() ? VISIBLE : GONE);
    this.attachmentButtonSpace.getLayoutParams().width = style.getAttachmentButtonMargin();

    this.messageSendButton.setImageDrawable(style.getInputButtonIcon());
    this.messageSendButton.getLayoutParams().width = style.getInputButtonWidth();
    this.messageSendButton.getLayoutParams().height = style.getInputButtonHeight();
    ViewCompat.setBackground(messageSendButton, style.getInputButtonBackground());
    this.sendButtonSpace.getLayoutParams().width = style.getInputButtonMargin();

    if (getPaddingLeft() == 0
            && getPaddingRight() == 0
            && getPaddingTop() == 0
            && getPaddingBottom() == 0) {
        setPadding(
                style.getInputDefaultPaddingLeft(),
                style.getInputDefaultPaddingTop(),
                style.getInputDefaultPaddingRight(),
                style.getInputDefaultPaddingBottom()
        );
    }
    this.delayTypingStatusMillis = style.getDelayTypingStatus();
}
 
Example 16
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setShapeBg(View view, int shape, GradientDrawable.Orientation orientation,
                              int[] bgColor, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(shape, orientation, bgColor, 0, 0, radius));
}
 
Example 17
Source File: ViewBgUtil.java    From SimpleProject with MIT License 4 votes vote down vote up
public static void setSelectorBg(View view, int state, int shape, GradientDrawable.Orientation[] orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, shape, orientation, bgColor, borderColor, borderWidth, radius));
}
 
Example 18
Source File: ViewBgUtil.java    From SimpleProject with MIT License 2 votes vote down vote up
/**
 * 设置与状态关联的背景 -> 有不同圆角的纯色背景
 * @param view
 * @param state
 * @param bgColor
 * @param radius
 */
public static void setSelectorBg(View view, int state, int[] bgColor, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(state, GradientDrawable.RECTANGLE, bgColor, radius));
}
 
Example 19
Source File: ViewBgUtil.java    From SimpleProject with MIT License 2 votes vote down vote up
/**
 * 设置与状态关联的背景 -> 有相同圆角的渐变背景
 * @param view
 * @param state
 * @param orientation
 * @param bgColor
 * @param borderColor
 * @param borderWidth
 * @param radius
 */
public static void setSelectorBg(View view, int state, GradientDrawable.Orientation orientation,
                                 int[][] bgColor, int[] borderColor, int borderWidth, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, GradientDrawable.RECTANGLE, orientation, bgColor,
			borderColor, borderWidth, radius));
}
 
Example 20
Source File: ViewBgUtil.java    From SimpleProject with MIT License 2 votes vote down vote up
/**
 * 设置与状态关联的背景 -> 有相同圆角的纯色背景
 * @param view
 * @param state
 * @param bgColor
 * @param radius
 */
public static void setSelectorBg(View view, int state, int[] bgColor, int radius) {
	ViewCompat.setBackground(view, getDrawable(state, GradientDrawable.RECTANGLE, bgColor, radius));
}