本文整理汇总了Java中android.view.View.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java View.setBackground方法的具体用法?Java View.setBackground怎么用?Java View.setBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addArrowView
import android.view.View; //导入方法依赖的package包/类
/**
* 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;
}
示例2: setBackgroundActiveColor
import android.view.View; //导入方法依赖的package包/类
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);
}
示例3: onFinishInflate
import android.view.View; //导入方法依赖的package包/类
@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);
}
}
示例4: blurAdvanced
import android.view.View; //导入方法依赖的package包/类
@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));
}
}
}
示例5: setRoundBackground
import android.view.View; //导入方法依赖的package包/类
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);
}
}
示例6: setBackground
import android.view.View; //导入方法依赖的package包/类
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);
}
}
示例7: setBackground
import android.view.View; //导入方法依赖的package包/类
@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);
}
}
示例8: applyViewTransitBackgroundColor
import android.view.View; //导入方法依赖的package包/类
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);
}
示例9: setBackground
import android.view.View; //导入方法依赖的package包/类
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);
}
}
示例10: setBackground
import android.view.View; //导入方法依赖的package包/类
public static void setBackground(View v, Drawable bgDrawable) {
if (VERSION.SDK_INT >= 16) {
v.setBackground(bgDrawable);
} else {
v.setBackgroundDrawable(bgDrawable);
}
}
示例11: setBackground
import android.view.View; //导入方法依赖的package包/类
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);
}
}
示例12: QuickActionViewLayout
import android.view.View; //导入方法依赖的package包/类
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);
}
}
}
示例13: drawBackground
import android.view.View; //导入方法依赖的package包/类
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);
}
}
示例14: setIndicatorTopContentView
import android.view.View; //导入方法依赖的package包/类
/**
* 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);
}
示例15: setBackgroundDrawableCompat
import android.view.View; //导入方法依赖的package包/类
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);
}
}