android.support.v4.view.ViewCompat#setBackground ( )源码实例Demo

下面列出了android.support.v4.view.ViewCompat#setBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: weMessage   文件: IncomingMessageViewHolder.java
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);
        }
    }
}
 
源代码2 项目: SwipeRecyclerView   文件: SwipeMenuView.java
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);
        }
    }
}
 
源代码3 项目: ChatKit   文件: MessageHolders.java
@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());
    }
}
 
源代码4 项目: ShadowDrawable   文件: ShadowDrawable.java
/**
 * 为指定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);
}
 
源代码5 项目: YCCardView   文件: ShadowView.java
/**
 * 初始化画笔操作
 */
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);
}
 
源代码6 项目: InstaTag   文件: InstaTag.java
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);
}
 
源代码7 项目: SwipeRecyclerView-master   文件: SwipeMenuView.java
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);
        }
    }
}
 
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) {
        }
    }
}
 
源代码9 项目: SimpleProject   文件: ViewBgUtil.java
public static void setShapeBg(View view, int shape, int bgColor, int radius) {
	ViewCompat.setBackground(view, getDrawable(shape, bgColor, radius));
}
 
源代码10 项目: SimpleProject   文件: ViewBgUtil.java
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));
}
 
源代码11 项目: ChatKit   文件: MessageInput.java
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();
}
 
源代码12 项目: SimpleProject   文件: ViewBgUtil.java
public static void setShapeBg(View view, int shape, int bgColor, float[] radius) {
	ViewCompat.setBackground(view, getDrawable(shape, bgColor, radius));
}
 
源代码13 项目: data-mediator   文件: AndroidBinder.java
@Override
protected void apply(Property prop, View view, Object newValue) {
    ViewCompat.setBackground(view, (Drawable) newValue);
}
 
源代码14 项目: KSnack   文件: MinimalKSnack.java
public MinimalKSnack setBackgrounDrawable(@NonNull @DrawableRes int drawableInt){
    // Set drawable to view.
    ViewCompat.setBackground(lnrSnack, ContextCompat.getDrawable(lnrSnack.getContext(), drawableInt));

    return this;
}
 
源代码15 项目: MiPushFramework   文件: BottomNavigationItemView.java
public void setItemBackground(int background) {
    Drawable backgroundDrawable = background == 0
            ? null : ContextCompat.getDrawable(getContext(), background);
    ViewCompat.setBackground(this, backgroundDrawable);
}
 
源代码16 项目: SimpleProject   文件: ViewBgUtil.java
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));
}
 
源代码17 项目: SimpleProject   文件: ViewBgUtil.java
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));
}
 
源代码18 项目: SimpleProject   文件: ViewBgUtil.java
/**
 * 设置与状态关联的背景 -> 有不同圆角的纯色背景
 * @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));
}
 
源代码19 项目: SimpleProject   文件: ViewBgUtil.java
/**
 * 设置与状态关联的背景 -> 有相同圆角的渐变背景
 * @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));
}
 
源代码20 项目: SimpleProject   文件: ViewBgUtil.java
/**
 * 设置与状态关联的背景 -> 有相同圆角的纯色背景
 * @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));
}
 
 同类方法