List of usage examples for android.graphics.drawable ColorDrawable setColor
public void setColor(@ColorInt int color)
From source file:Main.java
/** * Sets the color for a view with a colored background. In case the view's * background is not a {@link ColorDrawable}, or does not contain a * color-drawable in one of its layers, nothing happens. * //from ww w . ja v a 2 s. c om * @param view * @param color */ public static void setColor(View view, int color) { ColorDrawable colorDrawable = getColorDrawableBackground(view); if (colorDrawable != null) { colorDrawable.setColor(color); } }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.Util.java
public static void setColorToColorDrawable(ColorDrawable color, int colorValue) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { color.setColor(colorValue); } else {//from ww w .java 2 s . c om color.setColorFilter(colorValue, PorterDuff.Mode.SRC_ATOP); } }
From source file:im.ene.ribbon.MiscUtils.java
protected static void switchColor(final BottomNavigationView navigation, final View v, final View backgroundOverlay, final ColorDrawable backgroundDrawable, final int newColor) { backgroundOverlay.clearAnimation();/*ww w . j a va 2s . co m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Animator currentAnimator = (Animator) backgroundOverlay.getTag(R.id.ribbon_background_overlay_animator); if (null != currentAnimator) { currentAnimator.cancel(); } } backgroundDrawable.setColor(newColor); backgroundOverlay.setVisibility(View.INVISIBLE); ViewCompat.setAlpha(backgroundOverlay, 1); }
From source file:com.mobicage.rogerthat.util.ui.UIUtils.java
public static void setBackgroundColor(View view, int backgroundColor) { Drawable background = view.getBackground(); if (background instanceof ShapeDrawable) { ShapeDrawable shapeDrawable = (ShapeDrawable) background; shapeDrawable.getPaint().setColor(backgroundColor); } else if (background instanceof GradientDrawable) { GradientDrawable gradientDrawable = (GradientDrawable) background; gradientDrawable.setColor(backgroundColor); } else if (background instanceof ColorDrawable) { // alpha value may need to be set again after this call ColorDrawable colorDrawable = (ColorDrawable) background; colorDrawable.setColor(backgroundColor); } else {//from w ww . j a v a2 s. com L.e("Unknown background type to set color on: " + view.getClass()); } }
From source file:com.veggies.android.todoList.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); menuTexts = new String[] { "All Lists", "Default", "Personal", "Shopping", "Wishlist", "Work", "Unfinished" }; dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_list_white_24dp, menuTexts[0])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_list_white_24dp, menuTexts[1])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_person_pin_white_24dp, menuTexts[2])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_local_grocery_store_white_24dp, menuTexts[3])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_favorite_white_24dp, menuTexts[4])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_card_travel_white_24dp, menuTexts[5])); dropdownMenuItemList.add(new DropdownMenuItem(R.drawable.ic_highlight_off_white_24dp, menuTexts[6])); spinnerAdapter = new DropdownMenuItemAdapter(this, dropdownMenuItemList); //get the email passed by login UI Intent intent = this.getIntent(); mEmail = intent.getStringExtra(EMAIL); mTitle = mDrawerTitle = getTitle();//from w w w. j a v a 2 s. c om //put the drawer items in a hash map, so we can just use it to lookup index mDrawerItems = new HashMap<>(); String[] drawerArray = getResources().getStringArray(R.array.drawer_array); for (int i = 0; i < drawerArray.length; i++) { mDrawerItems.put(drawerArray[i], i); } drawerItemList.add(new DrawerItem(R.drawable.ic_list_white_24dp, "Todo List")); drawerItemList.add(new DrawerItem(R.drawable.ic_settings_white_24dp, "Setting")); BaseAdapter adapter = new DrawerItemAdapter(this, drawerItemList); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(adapter); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer ActionBar actionbar = getActionBar(); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeButtonEnabled(true); getActionBar().setIcon(R.drawable.logo_white); ColorDrawable colorDrawable = new ColorDrawable(); colorDrawable.setColor(0xff303F9F); getActionBar().setBackgroundDrawable(colorDrawable); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); if (listFragmentFlag) { setActionMenu(); } invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); hideActionMenu(); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:com.facebook.litho.reference.ColorDrawableReference.java
@Override protected Drawable onAcquire(ComponentContext context, Reference reference) { ColorDrawable drawable = null; if (CAN_RECYCLE) { drawable = sPool.acquire();/* w w w . jav a 2s .c om*/ } if (drawable == null) { drawable = new ColorDrawable(((State) reference).mColor); } else { drawable.setColor(((State) reference).mColor); } drawable.setAlpha(((State) reference).mAlpha); return drawable; }
From source file:com.jaredrummler.materialspinner.MaterialSpinner.java
@Override public void setBackgroundColor(int color) { backgroundColor = color;//from ww w . jav a 2 s .c o m Drawable background = getBackground(); if (background instanceof StateListDrawable) { // pre-L try { Method getStateDrawable = StateListDrawable.class.getDeclaredMethod("getStateDrawable", int.class); if (!getStateDrawable.isAccessible()) getStateDrawable.setAccessible(true); int[] colors = { darker(color, 0.85f), color }; for (int i = 0; i < colors.length; i++) { ColorDrawable drawable = (ColorDrawable) getStateDrawable.invoke(background, i); drawable.setColor(colors[i]); } } catch (Exception e) { Log.e("MaterialSpinner", "Error setting background color", e); } } else if (background != null) { // 21+ (RippleDrawable) background.setColorFilter(color, PorterDuff.Mode.SRC_IN); } popupWindow.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN); }
From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java
public void setToolBar(String name, Integer colorBg, Integer colorText) { mActionBarSet = true;//from www . ja v a 2 s . c o m MLog.d("mocmoc", "setting tolbar for " + name + " " + mActionbar); if (mActionbar != null) { // home clickable if is running inside protocoderapp if (AppSettings.STANDALONE == false) { //mToolbar.setDisplayHomeAsUpEnabled(true); setToolbarBack(); } // set color if (colorBg != null) { ColorDrawable d = new ColorDrawable(); d.setColor(colorBg); mActionbar.setBackgroundDrawable(d); } // title if (name != null) { mActionbar.setTitle(name); MLog.d("mocmoc2", "setting tolbar for " + name + " " + mToolbar); } // set title color if (colorText != null) { int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android"); TextView textTitleView = (TextView) findViewById(titleId); // apparently android-l doesnt have that resource if (textTitleView != null) { textTitleView.setTextColor(colorText); } } } }
From source file:im.ene.ribbon.AnimUtil.java
static void animate(BottomNavigationView parent, View view, final View backgroundOverlay, final ColorDrawable backgroundDrawable, final int newColor, long duration) { int centerX = (int) (ViewCompat.getX(view) + (view.getWidth() / 2)); int centerY = parent.getPaddingTop() + view.getHeight() / 2; backgroundOverlay.clearAnimation();// w w w. j a v a 2s . co m final Object animator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Animator currentAnimator = (Animator) backgroundOverlay.getTag(R.id.ribbon_background_overlay_animator); if (currentAnimator != null) { //currentAnimator.end(); currentAnimator.cancel(); } final float startRadius = 1; final float finalRadius = centerX > parent.getWidth() / 2 ? centerX : parent.getWidth() - centerX; animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY, startRadius, finalRadius); backgroundOverlay.setTag(R.id.ribbon_background_overlay_animator, animator); } else { ViewCompat.setAlpha(backgroundOverlay, 0); animator = ViewCompat.animate(backgroundOverlay).alpha(1); } backgroundOverlay.setBackgroundColor(newColor); backgroundOverlay.setVisibility(View.VISIBLE); if (animator instanceof ViewPropertyAnimatorCompat) { ((ViewPropertyAnimatorCompat) animator).setListener(new ViewPropertyAnimatorListener() { boolean cancelled; @Override public void onAnimationStart(final View view) { } @Override public void onAnimationEnd(final View view) { if (!cancelled) { backgroundDrawable.setColor(newColor); backgroundOverlay.setVisibility(View.INVISIBLE); ViewCompat.setAlpha(backgroundOverlay, 1); } } @Override public void onAnimationCancel(final View view) { cancelled = true; } }).setDuration(duration).start(); } else { Animator animator1 = (Animator) animator; animator1.setDuration(duration); animator1.setInterpolator(new DecelerateInterpolator()); animator1.addListener(new Animator.AnimatorListener() { boolean cancelled; @Override public void onAnimationStart(final Animator animation) { } @Override public void onAnimationEnd(final Animator animation) { if (!cancelled) { backgroundDrawable.setColor(newColor); backgroundOverlay.setVisibility(View.INVISIBLE); ViewCompat.setAlpha(backgroundOverlay, 1); } } @Override public void onAnimationCancel(final Animator animation) { cancelled = true; } @Override public void onAnimationRepeat(final Animator animation) { } }); animator1.start(); } }
From source file:com.yekertech.tvbarsetting.dialog.SettingsLayoutFragment.java
@Override public void onStart() { super.onStart(); if (!mEntryTransitionPerformed) { mEntryTransitionPerformed = true; performEntryTransition();/*w ww . j ava 2s.co m*/ } else { final View dialogView = getView(); final View contentView = (View) dialogView.getTag(R.id.content_fragment); int bgColor = contentView.getContext().getColor(R.color.lb_dialog_activity_background); final ColorDrawable bgDrawable = new ColorDrawable(); bgDrawable.setColor(bgColor); dialogView.setBackground(bgDrawable); } }