Java Code Examples for android.view.View.setBackgroundDrawable()

The following are Jave code examples for showing how to use setBackgroundDrawable() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenEyesReading-android   File: Util.java   View Source Code Vote up 6 votes
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);
    }

}
 
Example 2
Project: ShapedNavigationView   File: ShapedNavigationView.java   View Source Code Vote up 6 votes
@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());
            }
        }
    }
}
 
Example 3
Project: Android-Skin-Loader   File: BackgroundAttr.java   View Source Code Vote up 6 votes
@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());
	}
}
 
Example 4
Project: MVPArms_Fragment-fragment   File: FastBlur.java   View Source Code Vote up 6 votes
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");
}
 
Example 5
Project: SWDemo   File: ViewUtil.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 6
Project: airgram   File: ChatActivityEnterView.java   View Source Code Vote up 5 votes
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));
}
 
Example 7
Project: weex-uikit   File: WXViewUtils.java   View Source Code Vote up 5 votes
@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);
  }
}
 
Example 8
Project: easyfilemanager   File: ViewCompat.java   View Source Code Vote up 5 votes
@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);
	}
}
 
Example 9
Project: lrs_android   File: ViewUtil.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 10
Project: BBSSDK-for-Android   File: Helper.java   View Source Code Vote up 5 votes
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);
	}
}
 
Example 11
Project: CustomAndroidOneSheeld   File: ViewCompat.java   View Source Code Vote up 5 votes
public static void setBackground(View view, Drawable background) {
	if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
		SDK16.setBackground(view, background);
	} else {
		view.setBackgroundDrawable(background);
	}
}
 
Example 12
Project: Mire   File: TransitionAnimation.java   View Source Code Vote up 5 votes
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));
        }
    }
}
 
Example 13
Project: ShangHanLun   File: ATableView.java   View Source Code Vote up 5 votes
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);
        }
    }
 
Example 14
Project: FriendBook   File: PagerSlidingTabStrip.java   View Source Code Vote up 5 votes
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));
					}
				}
			}
		}

	}
 
Example 15
Project: MVPArms_Fragment-fragment   File: FragmentUtils.java   View Source Code Vote up 5 votes
/**
 * 设置背景
 *
 * @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);
        }
    }
}
 
Example 16
Project: simple-share-android   File: Utils.java   View Source Code Vote up 4 votes
public static void tintWidget(View view, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground());
    DrawableCompat.setTint(wrappedDrawable.mutate(), color);
    view.setBackgroundDrawable(wrappedDrawable);
}
 
Example 17
Project: chat-sdk-android-push-firebase   File: PickerFragment.java   View Source Code Vote up 4 votes
private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    logAppEvents(true);
                    appEventsLogged = true;

                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                    }
                }
            });

            if (getDoneButtonText() != null) {
                doneButton.setText(getDoneButtonText());
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (getTitleText() != null) {
                titleTextView.setText(getTitleText());
            }
        }
    }
}
 
Example 18
Project: CSipSimple   File: Utility4.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
public void setBackgroundDrawable(View v, Drawable d) {
    v.setBackgroundDrawable(d);
}
 
Example 19
Project: android_Json2view   File: AdapterHelper.java   View Source Code Vote up 4 votes
public void setBackground(int viewId, Drawable drawable) {
    View view = retrieveView(viewId);
    view.setBackgroundDrawable(drawable);
}
 
Example 20
Project: ankihelper   File: ViewUtil.java   View Source Code Vote up 4 votes
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);
}