本文整理汇总了Java中android.view.View.setBackgroundDrawable方法的典型用法代码示例。如果您正苦于以下问题:Java View.setBackgroundDrawable方法的具体用法?Java View.setBackgroundDrawable怎么用?Java View.setBackgroundDrawable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.setBackgroundDrawable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCircleButtonStateListDrawable
import android.view.View; //导入方法依赖的package包/类
public void setCircleButtonStateListDrawable(View circleButton, int radius,int color) {
WeakReference<Bitmap> imageNormal = new WeakReference<>(Bitmap.createBitmap(2 * radius, 2 * radius, Bitmap.Config.ARGB_8888));
Canvas canvasNormal = new Canvas(imageNormal.get());
Paint paintNormal = new Paint();
paintNormal.setAntiAlias(true);
paintNormal.setColor(color);
canvasNormal.drawCircle(radius, radius, radius, paintNormal);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(StateSet.WILD_CARD, new BitmapDrawable(circleButton.getContext().getResources(), imageNormal.get()));
if (android.os.Build.VERSION.SDK_INT >= 16) {
circleButton.setBackground(stateListDrawable);
} else {
circleButton.setBackgroundDrawable(stateListDrawable);
}
}
示例2: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View v = getChildAt(i);
if (v instanceof NavigationMenuView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
v.setBackground(settings.getBackgroundDrawable());
} else {
v.setBackgroundDrawable(settings.getBackgroundDrawable());
}
}
}
}
示例3: apply
import android.view.View; //导入方法依赖的package包/类
@Override
public void apply(View view) {
if(RES_TYPE_NAME_COLOR.equals(attrValueTypeName)){
view.setBackgroundColor(SkinManager.getInstance().getColor(attrValueRefId));
Log.i("attr", "_________________________________________________________");
Log.i("attr", "apply as color");
}else if(RES_TYPE_NAME_DRAWABLE.equals(attrValueTypeName)){
Drawable bg = SkinManager.getInstance().getDrawable(attrValueRefId);
view.setBackgroundDrawable(bg);
Log.i("attr", "_________________________________________________________");
Log.i("attr", "apply as drawable");
Log.i("attr", "bg.toString() " + bg.toString());
Log.i("attr", this.attrValueRefName + " 是否可变换状态? : " + bg.isStateful());
}
}
示例4: blur
import android.view.View; //导入方法依赖的package包/类
public static void blur(Context context, Bitmap bkg, View view) {
long startMs = System.currentTimeMillis();
float radius = 15;
float scaleFactor = 8;
//放大到整个view的大小
bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
, (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bkg, 0, 0, paint);
overlay = FastBlur.doBlur(overlay, (int) radius, true);
view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
示例5: 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);
}
}
示例6: addToAttachLayout
import android.view.View; //导入方法依赖的package包/类
public void addToAttachLayout(View view) {
if (attachButton == null) {
return;
}
if (view.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) view.getParent();
viewGroup.removeView(view);
}
if (Build.VERSION.SDK_INT >= 21) {
view.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
}
attachButton.addView(view, LayoutHelper.createLinear(48, 48));
}
示例7: setBackGround
import android.view.View; //导入方法依赖的package包/类
@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);
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: setBackground
import android.view.View; //导入方法依赖的package包/类
public static void setBackground(View view, Drawable background) {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
SDK16.setBackground(view, background);
} else {
view.setBackgroundDrawable(background);
}
}
示例11: setImageToView
import android.view.View; //导入方法依赖的package包/类
private static void setImageToView(View toView, Bitmap bitmap) {
if (toView instanceof ImageView) {
final ImageView toImageView = (ImageView) toView;
toImageView.setImageBitmap(bitmap);
} else {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
toView.setBackground(new BitmapDrawable(toView.getResources(), bitmap));
} else {
toView.setBackgroundDrawable(new BitmapDrawable(toView.getResources(), bitmap));
}
}
}
示例12: setupFooterView
import android.view.View; //导入方法依赖的package包/类
private void setupFooterView(int lastRowHeight) {
// closes #12, add footer for plain style tables in order to make the
// effect of repeating
// rows across table height.
if (mStyle == ATableViewStyle.Plain) {
final View footerView = new FrameLayout(getContext());
// add listener to resize after layout has been completed.
getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
getViewTreeObserver().removeGlobalOnLayoutListener(
this);
int footerHeight = getHeight()
- getInternalAdapter().getContentHeight();
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT,
footerHeight > 0 ? footerHeight : 0);
footerView.setLayoutParams(params);
}
});
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk > android.os.Build.VERSION_CODES.JELLY_BEAN) {
footerView.setBackground(new ATableViewPlainFooterDrawable(
this, lastRowHeight));
} else {
footerView
.setBackgroundDrawable(new ATableViewPlainFooterDrawable(
this, lastRowHeight));
}
addFooterView(footerView);
}
}
示例13: updateTabStyles
import android.view.View; //导入方法依赖的package包/类
private void updateTabStyles() {
for (int i = 0; i < tabCount; i++) {
View v = tabsContainer.getChildAt(i);
if (tabBackgroundResId != -1) {
//v.setBackgroundResource(tabBackgroundResId);
v.setBackgroundDrawable(ContextCompat.getDrawable(getContext(),tabBackgroundResId));
}
if (v instanceof TextView) {
TextView tab = (TextView) v;
tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
tab.setTypeface(tabTypeface, tabTypefaceStyle);
if (pager.getCurrentItem() == i) {
pageSelected=i;
tab.setTextColor(tabSelectTextColor);
} else {
tab.setTextColor(tabUnSelectTextColor);
}
// setAllCaps() is only available from API 14, so the upper case
// is made manually if we are on a
// pre-ICS-build
if (textAllCaps) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
tab.setAllCaps(true);
} else {
tab.setText(tab.getText().toString()
.toUpperCase(locale));
}
}
}
}
}
示例14: setBackground
import android.view.View; //导入方法依赖的package包/类
/**
* 设置背景
*
* @param fragment fragment
* @param background 背景
*/
public static void setBackground(@NonNull Fragment fragment, Drawable background) {
View view = fragment.getView();
if (view != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(background);
} else {
view.setBackgroundDrawable(background);
}
}
}
示例15: tintWidget
import android.view.View; //导入方法依赖的package包/类
public static void tintWidget(View view, int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground());
DrawableCompat.setTint(wrappedDrawable.mutate(), color);
view.setBackgroundDrawable(wrappedDrawable);
}