List of usage examples for android.graphics.drawable Drawable setTintList
public void setTintList(@Nullable ColorStateList tint)
From source file:com.landenlabs.all_UiDemo.frag.RadioBtnFrag.java
private void addTabBar(RadioGroup tabHolder, float weight, int padding) { final int maxTabs = 4; // tabHolder.removeAllViews(); int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }; ColorStateList colorStateList = new ColorStateList(states, new int[] { 0xff00ff00, 0x80ff0000 }); RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, weight); /*//from w w w .j a v a2 s. co m ViewOutlineProvider outlineBoundary; if (Build.VERSION.SDK_INT >= 21) { outlineBoundary = new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setRect(0, 0, 200, 60); // view.getMeasuredWidth(), view.getMeasuredHeight()); } }; } */ String[] pageNames = new String[] { "Home", "Map", "Hourly", "Daily" }; int tabCnt = 0; for (String pageName : pageNames) { RadioButton button = new RadioButton(tabHolder.getContext()); String resName = "tab_" + pageName.toLowerCase(); int resID = getResources().getIdentifier(resName, "drawable", this.getContext().getPackageName()); Drawable tabBtnIcon = getResources().getDrawable(resID); if (tabBtnIcon != null) { if (tabBtnIcon != null && Build.VERSION.SDK_INT >= 21) { tabBtnIcon.setTintMode(PorterDuff.Mode.MULTIPLY); tabBtnIcon.setTintList(colorStateList); } else { tabBtnIcon = DrawableCompat.wrap(tabBtnIcon); DrawableCompat.setTintList(tabBtnIcon.mutate(), colorStateList); DrawableCompat.setTintMode(tabBtnIcon.mutate(), PorterDuff.Mode.MULTIPLY); } // tabBtnIcon = tabHolder.getResources().getDrawable(android.R.drawable.btn_radio); if (Build.VERSION.SDK_INT >= 21) { // Hide standard radio button but leave ripple effect button.setButtonDrawable(null); } else { // Hide standard radio button button.setButtonDrawable(new StateListDrawable()); } button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); /* // button.setBackgroundResource(R.drawable.ripple_boarderless); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); // button.setCompoundDrawablesRelativeWithIntrinsicBounds(null, tabBtnIcon, null, null); // tabBtnIcon.setBounds(0, 0, 50, 100); // img.getMinimumWidth(), img.getMinimumHeight()); // button.setCompoundDrawables(null, tabBtnIcon, null, null); } else { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); } */ button.setBackgroundResource(R.drawable.ripple_boarderless); button.setPadding(padding, padding, padding, padding); button.setGravity(Gravity.CENTER); button.setTextColor(colorStateList); button.setText(pageName); tabHolder.addView(button, lp); if (++tabCnt == maxTabs) break; } } }
From source file:com.xabber.android.ui.adapter.ChatMessageAdapter.java
private void setUpMessageBalloonBackground(View messageBalloon, ColorStateList darkColorStateList, int lightBackgroundId) { if (SettingsManager.interfaceTheme() == SettingsManager.InterfaceTheme.dark) { final Drawable originalBackgroundDrawable = messageBalloon.getBackground(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { originalBackgroundDrawable.setTintList(darkColorStateList); } else {/* w w w. j ava 2 s .c o m*/ Drawable wrapDrawable = DrawableCompat.wrap(originalBackgroundDrawable); DrawableCompat.setTintList(wrapDrawable, darkColorStateList); int pL = messageBalloon.getPaddingLeft(); int pT = messageBalloon.getPaddingTop(); int pR = messageBalloon.getPaddingRight(); int pB = messageBalloon.getPaddingBottom(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { messageBalloon.setBackground(wrapDrawable); } else { messageBalloon.setBackgroundDrawable(wrapDrawable); } messageBalloon.setPadding(pL, pT, pR, pB); } } else { int pL = messageBalloon.getPaddingLeft(); int pT = messageBalloon.getPaddingTop(); int pR = messageBalloon.getPaddingRight(); int pB = messageBalloon.getPaddingBottom(); messageBalloon.setBackgroundResource(lightBackgroundId); messageBalloon.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account)); messageBalloon.setPadding(pL, pT, pR, pB); } }