android.view.View#setBackground ( )源码实例Demo

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

源代码1 项目: base-module   文件: BlurHelper.java
private static void autoHandleSuccess(final Bitmap bitmap, final BlurConfig blurConfig) {
    if (blurConfig.cache && !TextUtils.isEmpty(blurConfig.cacheKey)) {
        addCacheBitmap(blurConfig.cacheKey, bitmap);
    }
    if (blurConfig.targetView != null && blurConfig.targetView.get() != null) {
        View target = blurConfig.targetView.get();
        if (target instanceof ImageView) {
            ((ImageView)target).setImageBitmap(bitmap);
        } else {
            Drawable drawable = new BitmapDrawable(target.getContext().getResources(), bitmap);
            if (Build.VERSION.SDK_INT <= 16) {
                target.setBackgroundDrawable(drawable);
            } else {
                target.setBackground(drawable);
            }
        }
        if (blurConfig.animAlpha) {
            animate(target, blurConfig.animDuration);
        }
    }
}
 
源代码2 项目: support   文件: TagFlowLayout.java
private void updateCheckStatus(View view, boolean checked) {
    if (view == null) {
        return;
    }
    // don't reuse drawable for different tag label
    Drawable[] drawables = mDecorator.getBackgroundDrawable();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(drawables[drawables.length > 1 ? (checked ? 1 : 0) : 0]);
    } else {
        view.setBackground(drawables[drawables.length > 1 ? (checked ? 1 : 0) : 0]);
    }
    final int[] color = mDecorator.getTextColor();
    if (color != null && color.length > 0) {
        ((TextView) view).setTextColor((color[color.length > 1 ? (checked ? 1 : 0) : 0]));
    }
}
 
源代码3 项目: weex-uikit   文件: WXViewUtils.java
@SuppressWarnings("deprecation")
public static void setBackGround(View view, Drawable drawable){
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN){
    view.setBackgroundDrawable(drawable);
  }
  else{
    view.setBackground(drawable);
  }
}
 
源代码4 项目: commcare-android   文件: ViewUtil.java
/**
 * Sets the background on a view to the provided drawable while retaining the padding
 * of the original view (regardless of whether the provided drawable has its own padding)
 *
 * @param v          The view whose background will be updated
 * @param background A background drawable (can be null to clear the background)
 */
public static void setBackgroundRetainPadding(View v, Drawable background) {
    //Need to transplant the padding due to background affecting it
    int[] padding = {v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom()};

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        v.setBackground(background);
    } else {
        v.setBackgroundDrawable(background);
    }
    v.setPadding(padding[0], padding[1], padding[2], padding[3]);
}
 
源代码5 项目: SegmentedButton   文件: RippleHelper.java
static void setRipple(View view, int pressedColor, Integer normalColor, int radius) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setBackground(getRippleDrawable(pressedColor, normalColor, radius));
    } else {
        view.setBackgroundDrawable(getStateListDrawable(pressedColor, normalColor, radius));
    }
}
 
源代码6 项目: PreviewSeekBar   文件: PreviewMorphAnimator.java
private void tintViews(PreviewBar previewBar,
                       View morphView,
                       View frameView) {
    int color = previewBar.getScrubberColor();
    if (morphView.getBackgroundTintList() == null
            || morphView.getBackgroundTintList().getDefaultColor() != color) {
        Drawable drawable = DrawableCompat.wrap(morphView.getBackground());
        DrawableCompat.setTint(drawable, color);
        morphView.setBackground(drawable);
        frameView.setBackgroundColor(color);
    }
}
 
源代码7 项目: RadioRealButton   文件: BackgroundHelper.java
static void setBackground(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
源代码8 项目: AcDisplay   文件: RippleDrawable.java
@SuppressWarnings("deprecation")
private static void setBackground(View target, Drawable drawable) {
    if (Build.VERSION.SDK_INT > 16) {
        target.setBackground(drawable);
    } else {
        target.setBackgroundDrawable(drawable);
    }
}
 
源代码9 项目: Primary   文件: HorzItemList.java
private void setBackground(View item, int drawableId) {
    if (Build.VERSION.SDK_INT >= 21) {
        item.setBackground(mParent.getResources().getDrawable(android.R.drawable.btn_default, mParent.getTheme()));
    } else {
        item.setBackground(mParent.getResources().getDrawable(android.R.drawable.btn_default));
    }

}
 
源代码10 项目: heads-up   文件: ThemeClass.java
protected static void setColor(View view, int color) {
    if (color == 0) return;
    Drawable drawable = view.getBackground();
    if (drawable != null) {
        drawable = drawable.mutate();
        //drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        drawable.setColorFilter(getColorFilter(color));
        if (Build.VERSION.SDK_INT >= 16) view.setBackground(drawable);
        else                             view.setBackgroundDrawable(drawable);
    } else {
        view.setBackgroundColor(color);
    }
}
 
源代码11 项目: google-io-2014-compat   文件: Utils.java
@SuppressWarnings("deprecation")
public static void setBackgroundCompat(View v, Drawable drawable) {
    if (hasJellyBean()) {
        v.setBackground(drawable);
    } else {
        v.setBackgroundDrawable(drawable);
    }
}
 
源代码12 项目: UltimateAndroid   文件: RippleDrawable.java
private static void setBackground(View target, Drawable drawable){
    if(Build.VERSION.SDK_INT > 16){
        target.setBackground(drawable);
    }else{
        target.setBackgroundDrawable(drawable);
    }
}
 
源代码13 项目: delion   文件: ChromeSwitchPreference.java
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    if (mDrawDivider) {
        int left = view.getPaddingLeft();
        int right = view.getPaddingRight();
        int top = view.getPaddingTop();
        int bottom = view.getPaddingBottom();
        view.setBackground(DividerDrawable.create(getContext()));
        view.setPadding(left, top, right, bottom);
    }

    SwitchCompat switchView = (SwitchCompat) view.findViewById(R.id.switch_widget);
    // On BLU Life Play devices SwitchPreference.setWidgetLayoutResource() does nothing. As a
    // result, the user will see a non-material Switch and switchView will be null, hence the
    // null check below. http://crbug.com/451447
    if (switchView != null) {
        switchView.setChecked(isChecked());
    }

    TextView title = (TextView) view.findViewById(android.R.id.title);
    title.setSingleLine(false);
    if (!mDontUseSummaryAsTitle && TextUtils.isEmpty(getTitle())) {
        TextView summary = (TextView) view.findViewById(android.R.id.summary);
        title.setText(summary.getText());
        title.setVisibility(View.VISIBLE);
        summary.setVisibility(View.GONE);
    }

    if (mManagedPrefDelegate != null) mManagedPrefDelegate.onBindViewToPreference(this, view);
}
 
源代码14 项目: talk-android   文件: DialogUtils.java
@SuppressLint("NewApi")
public static void setBackgroundCompat(View view, Drawable d) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        view.setBackgroundDrawable(d);
    } else {
        view.setBackground(d);
    }
}
 
源代码15 项目: Muzesto   文件: PlayTransition.java
private View addViewToOverlay(ViewGroup sceneRoot, int width, int height, Drawable background) {
    View view = new NoOverlapView(sceneRoot.getContext());
    view.setBackground(background);
    int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
    view.measure(widthSpec, heightSpec);
    view.layout(0, 0, width, height);
    sceneRoot.getOverlay().add(view);
    return view;
}
 
源代码16 项目: budget-envelopes   文件: SimpleEnvelopesAdapter.java
private void changeColor(int pos, View change) {
    Cursor csr = getCursor();
    csr.moveToPosition(pos);
    int color = csr.getInt(csr.getColumnIndexOrThrow("color"));
    if(sdkVersion < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        change.setBackgroundDrawable(EnvelopesAdapter.getColorStateDrawable(color));
    } else {
        change.setBackground(EnvelopesAdapter.getColorStateDrawable(color));
    }
}
 
void setBackgroundCompat(View view, Drawable d) {
    view.setBackground(d);
}
 
源代码18 项目: RxTools-master   文件: RxToast.java
public static final void setBackground(@NonNull View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        view.setBackground(drawable);
    else
        view.setBackgroundDrawable(drawable);
}
 
源代码19 项目: music_player   文件: MainActivity.java
public void animation_change_color(final int Int) {
    ImageView play_now_back_color = (ImageView) findViewById(R.id.play_now_back_color);
    final RelativeLayout activity_now_play = (RelativeLayout) findViewById(R.id.activity_now_play);
    if (cx == 0) {
        FloatingActionButton play_or_pause = (FloatingActionButton) findViewById(R.id.play_or_pause);
        RelativeLayout seekbar_layout = (RelativeLayout) findViewById(R.id.seekbar_layout);
        RelativeLayout control_layout = (RelativeLayout) findViewById(R.id.control_layout);
        cx = play_or_pause.getLeft() + control_layout.getLeft() + play_or_pause.getWidth() / 2;
        cy = control_layout.getTop() - seekbar_layout.getTop() + play_or_pause.getTop() + play_or_pause.getHeight() / 2;
        finalRadius = Math.max(play_now_back_color.getWidth(), play_now_back_color.getHeight());
    }
    if (cx != 0) {
        Animator anim = ViewAnimationUtils.createCircularReveal(play_now_back_color, cx, cy, 0, finalRadius);
        play_now_back_color.setBackgroundColor(Int);
        anim.setDuration(500);
        anim.start();
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                activity_now_play.setBackgroundColor(Int);
            }
        });
    } else {
        activity_now_play.setBackgroundColor(Int);
    }
    TextView now_on_play_text = (TextView) findViewById(R.id.now_on_play_text);
    now_on_play_text.setTextColor(Int);
    //lrcview字体颜色
    if (ColorUtil.isColorLight(Int)) {
        otherLyricView.setNormalColor(Color.parseColor("#60000000"));
        otherLyricView.setTimelineTextColor(Color.parseColor("#000000"));
        otherLyricView.setCurrentColor(Color.parseColor("#000000"));
    } else {
        otherLyricView.setNormalColor(Color.parseColor("#60FFFFFF"));
        otherLyricView.setTimelineTextColor(Color.parseColor("#FFFFFF"));
        otherLyricView.setCurrentColor(Color.parseColor("#FFFFFF"));
    }

    //歌词背景颜色
    if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        View bottom = findViewById(R.id.gradient_bottom);
        View top = findViewById(R.id.gradient_top);
        View gradient = findViewById(R.id.gradient);
        top.setBackground(
                ScrimUtil.makeCubicGradientScrimDrawable(Int, //颜色
                        8, //渐变层数
                        Gravity.TOP)); //起始方向
        bottom.setBackground(
                ScrimUtil.makeCubicGradientScrimDrawable(Int, //颜色
                        8, //渐变层数
                        Gravity.BOTTOM)); //起始方向
        gradient.setBackground(
                ScrimUtil.makeCubicGradientScrimDrawable(Int, //颜色
                        8, //渐变层数
                        Gravity.BOTTOM)); //起始方向
    }
}
 
源代码20 项目: SwipeBack   文件: ModSDK21.java
@TargetApi(21)
public static void afterOnPostCreateSDK21(XC_MethodHook.MethodHookParam mhparams) throws Throwable {
	Class<?> internalStyleable = findClass("com.android.internal.R.styleable", null);
	int[] internalTheme = $(getStaticObjectField(internalStyleable, "Theme"));
	int internalColorPrimary = getStaticIntField(internalStyleable, "Theme_colorPrimaryDark");
	
	SwipeBackActivityHelper helper = $(getAdditionalInstanceField(mhparams.thisObject, "helper"));
	if (helper != null) {
		final Activity activity = $(mhparams.thisObject);

		String packageName = activity.getApplicationInfo().packageName;
		String className = activity.getClass().getName();
		
		mSettings.reload();
		if (!mSettings.getBoolean(packageName, className, Settings.LOLLIPOP_HACK, false))
			return;
		
		ViewGroup root = $(helper.getSwipeBackLayout().getChildAt(0));
		View content = root.getChildAt(0);
		final WindowInsetsColorDrawable bkg = new WindowInsetsColorDrawable(content.getBackground());
		content.setBackground(bkg);
		
		TypedArray a = activity.getTheme().obtainStyledAttributes(internalTheme);
		int primary = a.getColor(internalColorPrimary, 0);
		a.recycle();

		if (primary != 0) {
			bkg.setTopDrawable(new ColorDrawable(primary));
		} else {
			content.setSystemUiVisibility(content.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
			content.setFitsSystemWindows(true);
		}

		root.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
			@Override
			public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
				bkg.setTopInset(insets.getSystemWindowInsetTop());
				activity.getWindow().setStatusBarColor(0);
				return insets;
			}
		});
	}
}
 
 方法所在类
 同类方法