List of usage examples for android.view View setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:Main.java
public static void setBackgroundResource(final View v, final int resource) { final int padLeft = v.getPaddingLeft(); final int padRight = v.getPaddingRight(); final int padTop = v.getPaddingRight(); final int padBottom = v.getPaddingBottom(); v.setBackgroundResource(resource); v.setPadding(padLeft, padTop, padRight, padBottom); }
From source file:android.support.v7.testutils.AppCompatTintableViewActions.java
/** * Sets background resource on a <code>View</code> that implements the * <code>TintableBackgroundView</code> interface. */// ww w. j av a2 s .c o m public static ViewAction setBackgroundResource(final @DrawableRes int resId) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return allOf(TestUtilsMatchers.isTintableBackgroundView()); } @Override public String getDescription() { return "set background resource"; } @Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); view.setBackgroundResource(resId); uiController.loopMainThreadUntilIdle(); } }; }
From source file:Main.java
public static void setBackground(View view, int background) { if (view == null) { return;/*from w w w. ja v a 2s . c o m*/ } int left = view.getPaddingLeft(); int right = view.getPaddingRight(); int top = view.getPaddingTop(); int bottom = view.getPaddingBottom(); view.setBackgroundResource(background); view.setPadding(left, top, right, bottom); }
From source file:com.waz.zclient.utils.ViewUtils.java
@TargetApi(14) @SuppressLint("NewApi") public static void setBackground(Context context, View view, int resource) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { view.setBackgroundResource(resource); } else {/*ww w. j av a2s . c o m*/ view.setBackground(context.getResources().getDrawable(resource)); } }
From source file:Main.java
public static void makeListItemClickable(View listItem, OnClickListener onRowClick) { listItem.setClickable(true);/* w ww.j av a2 s.c om*/ listItem.setFocusable(true); // setBackgroundResource seems to reset padding... // http://stackoverflow.com/questions/5890379/android-setbackgroundresource-discards-my-xml-layout-attributes // so manually save and restore them int padLeft = listItem.getPaddingLeft(); int padRight = listItem.getPaddingRight(); int padTop = listItem.getPaddingTop(); int padBottom = listItem.getPaddingBottom(); listItem.setBackgroundResource(android.R.drawable.menuitem_background); listItem.setPadding(padLeft, padTop, padRight, padBottom); listItem.setOnClickListener(onRowClick); }
From source file:Main.java
/** * /*from w w w. j a v a 2s . c o m*/ * @param context * @param view * @param resid * @return */ public static View addBackgroundIndicator(Context context, View view, int resid) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { TypedArray attributes = context.obtainStyledAttributes(new int[] { resid }); int resource = attributes.getResourceId(0, 0); attributes.recycle(); // setBackgroundResource resets padding int paddingLeft = view.getPaddingLeft(); int paddingTop = view.getPaddingTop(); int paddingRight = view.getPaddingRight(); int paddingBottom = view.getPaddingBottom(); view.setBackgroundResource(resource); view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } return view; }
From source file:fr.shywim.antoinedaniel.utils.Utils.java
/** * First part of the click animation.// w ww . j a v a 2 s. co m * * @param context Any context. * @param v View who will have the effect. * @param isRoot Whether the passed view is the ViewGroup parent. */ public static void clickAnimDown(Context context, View v, boolean isRoot) { RelativeLayout root; if (isRoot) root = (RelativeLayout) v; else root = (RelativeLayout) v.getParent(); final View rectView = new View(context); rectView.setId(R.id.rect_view_id); rectView.setVisibility(View.GONE); rectView.setBackgroundResource(R.drawable.square); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(v.getMeasuredWidth(), v.getMeasuredHeight()); params.addRule(RelativeLayout.ALIGN_TOP, v.getId()); rectView.setLayoutParams(params); AlphaAnimation rectAnim = new AlphaAnimation(0f, 0.4f); rectAnim.setFillAfter(true); rectAnim.setInterpolator(new AccelerateInterpolator()); rectAnim.setDuration(150); rectAnim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { rectView.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); root.addView(rectView); rectView.startAnimation(rectAnim); }
From source file:android.support.v17.leanback.supportleanbackshowcase.cards.CharacterCardView.java
public CharacterCardView(Context context) { super(context, null, R.style.CharacterCardStyle); LayoutInflater.from(getContext()).inflate(R.layout.character_card, this); setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override/*www. j av a 2 s . c o m*/ public void onFocusChange(View v, boolean hasFocus) { ImageView mainImage = (ImageView) findViewById(R.id.main_image); View container = findViewById(R.id.container); if (hasFocus) { container.setBackgroundResource(R.drawable.character_focused); mainImage.setBackgroundResource(R.drawable.character_focused); } else { container.setBackgroundResource(R.drawable.character_not_focused_padding); mainImage.setBackgroundResource(R.drawable.character_not_focused); } } }); setFocusable(true); }
From source file:com.fuzz.emptyhusk.prefab.ProportionalImageCellGenerator.java
@Override public void onBindChild(@NonNull View child, @NonNull CutoutViewLayoutParams lp, @Nullable View originator) { child.setBackgroundResource(lp.cellBackgroundId); if (originator != null) { rvChildLength = originator.getHeight(); if (originator.getParent() instanceof ViewGroup) { rvLength = ((ViewGroup) originator.getParent()).getHeight(); }/*from ww w. j av a 2 s. co m*/ } if (child instanceof ImageView) { GradientDrawable elongated = new GradientDrawable(); elongated.setShape(GradientDrawable.RECTANGLE); int accent = ContextCompat.getColor(child.getContext(), R.color.transparentColorAccent); float fractionOfParent = rvLength * 1.0f / rvChildLength; elongated.setColor(accent); float proposedLength = fractionOfParent * lp.perpendicularLength; elongated.setSize(lp.perpendicularLength, (int) proposedLength); ((ImageView) child).setImageDrawable(elongated); } }
From source file:com.druk.bonjour.browser.ui.adapter.TxtRecordsAdapter.java
@Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.two_text_item, viewGroup, false); view.setBackgroundResource(mBackground); return new ViewHolder(view); }