List of usage examples for android.content.res ColorStateList ColorStateList
public ColorStateList(int[][] states, @ColorInt int[] colors)
From source file:com.tr4android.support.extension.picker.PickerThemeUtils.java
public static ColorStateList getNavButtonColorStateList(Context context) { return new ColorStateList(new int[][] { // states new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_focused }, new int[] {} // state_default }, new int[] { //colors ThemeUtils.getThemeAttrColor(context, R.attr.colorControlHighlight), ThemeUtils.getThemeAttrColor(context, R.attr.colorControlHighlight), ContextCompat.getColor(context, android.R.color.transparent) }); }
From source file:at.linuxtage.companion.widgets.SlidingTabLayout.java
private static ColorStateList createColorStateList(int defaultColor, int selectedColor) { final int[] colors = new int[] { selectedColor, defaultColor }; return new ColorStateList(TAB_COLOR_STATES, colors); }
From source file:com.tompee.funtablayout.FlipTabAdapter.java
private Drawable loadIconWithTint(Context context, @DrawableRes int resourceId) { Drawable icon = ContextCompat.getDrawable(context, resourceId); ColorStateList colorStateList;//from ww w . j ava2 s . co m int[][] states = new int[][] { new int[] { android.R.attr.state_selected }, new int[] { -android.R.attr.state_empty } }; int[] colors = new int[] { mTabIndicatorColor, mDefaultIconColor }; colorStateList = new ColorStateList(states, colors); icon = DrawableCompat.wrap(icon); DrawableCompat.setTintList(icon, colorStateList); return icon; }
From source file:com.himotech.matrialdesign.HomeActivity.java
private void initView() { mMopubView = (MoPubView) findViewById(R.id.adview); //b35ad8db407a4961a93be42b48a09459 mMopubView.setAdUnitId("b35ad8db407a4961a93be42b48a09459"); mMopubView.setAutorefreshEnabled(true); mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), this); mViewPager = (ViewPager) findViewById(R.id.viewpager); mViewPager.setAdapter(mPagerAdapter); mMopubView.setBannerAdListener(new MoPubView.BannerAdListener() { @Override//from ww w.j ava 2s. c o m public void onBannerLoaded(MoPubView banner) { Toast.makeText(getApplicationContext(), "Banner successfully loaded.", Toast.LENGTH_SHORT).show(); } @Override public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) { } @Override public void onBannerClicked(MoPubView banner) { } @Override public void onBannerExpanded(MoPubView banner) { } @Override public void onBannerCollapsed(MoPubView banner) { } }); mMopubView.loadAd(); int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, // enabled new int[] { -android.R.attr.state_enabled }, // disabled new int[] { -android.R.attr.state_checked }, // unchecked new int[] { android.R.attr.state_pressed } // pressed }; int[] colors = new int[] { getResources().getColor(R.color.tab_bg), getResources().getColor(R.color.tab_bg), Color.GREEN, Color.BLUE }; ColorStateList myList = new ColorStateList(states, colors); mAppCampatBtn = (AppCompatButton) findViewById(R.id.btn_next_screen); mToolBarHome = (Toolbar) findViewById(com.himotech.matrialdesign.R.id.toolbar_home); mToolBarHome.setTitle(com.himotech.matrialdesign.R.string.app_name); //mRecyclerView=(RecyclerView)findViewById(com.himotech.matrialdesign.R.id.list_recycle); mFloatingAb = (FloatingActionButton) findViewById(com.himotech.matrialdesign.R.id.floatin_ab_home); //mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mTabLayout = (TabLayout) findViewById(com.himotech.matrialdesign.R.id.tab_layout); /*mTabLayout.addTab(mTabLayout.newTab().setCustomView(R.layout.custom_tab_layout)); mTabLayout.addTab(mTabLayout.newTab().setCustomView(R.layout.custom_tab_layout)); mTabLayout.addTab(mTabLayout.newTab().setCustomView(R.layout.custom_tab_layout));*/ mTabLayout.addTab(mTabLayout.newTab().setText("Tab One")); mTabLayout.addTab(mTabLayout.newTab().setText("Tab Two")); mTabLayout.addTab(mTabLayout.newTab().setText("Tab Third")); // mTabLayout.setTabsFromPagerAdapter(mPagerAdapter); mTabLayout.setupWithViewPager(mViewPager); mHomeListAdapter = new HomeListAdapter(); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { //mTabLayout.setScrollPosition(position,positionOffset,true); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); //mRecyclerView.setAdapter(mHomeListAdapter); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mAppCampatBtn.setSupportBackgroundTintList(myList); } else { mAppCampatBtn.setSupportBackgroundTintList(myList); ViewCompat.setBackgroundTintList(mAppCampatBtn, myList); } }
From source file:arun.com.popularmovies.MovieDetailActivity.java
private void updateFAB(int darkVibrant) { mFaB.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { 0 } }, new int[] { darkVibrant })); showFAB();/*from ww w . ja v a2 s. c om*/ }
From source file:com.bilibili.magicasakura.utils.ColorStateListUtils.java
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { final int innerDepth = parser.getDepth() + 1; int depth;//w w w. ja v a 2s . c o m int type; LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) { continue; } TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color }); final int value = a1.getResourceId(0, Color.MAGENTA); final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value); a1.recycle(); TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha }); final float alphaMod = a2.getFloat(0, 1.0f); a2.recycle(); colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor); stateList.add(extractStateSet(attrs)); } if (stateList.size() > 0 && stateList.size() == colorList.size()) { int[] colors = new int[colorList.size()]; for (int i = 0; i < colorList.size(); i++) { colors[i] = colorList.get(i); } return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors); } return null; }
From source file:com.facebook.react.views.checkbox.ReactCheckBoxManager.java
@ReactProp(name = "tintColors") public void setTintColors(ReactCheckBox view, @Nullable ReadableMap colorsMap) { String defaultColorIdOfCheckedState = "colorAccent"; int trueColor = colorsMap == null || !colorsMap.hasKey("true") ? getThemeColor(view.getContext(), defaultColorIdOfCheckedState) : colorsMap.getInt("true"); String defaultColorIdOfUncheckedState = "colorPrimaryDark"; int falseColor = colorsMap == null || !colorsMap.hasKey("false") ? getThemeColor(view.getContext(), defaultColorIdOfUncheckedState) : colorsMap.getInt("false"); ColorStateList csl = new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] { -android.R.attr.state_checked } }, new int[] { trueColor, falseColor, }); CompoundButtonCompat.setButtonTintList(view, csl); }
From source file:com.github.dfa.diaspora_android.ui.theme.ThemeHelper.java
public static void updateRadioGroupColor(RadioGroup radioGroup) { if (radioGroup != null && Build.VERSION.SDK_INT >= 21) { for (int i = 0; i < radioGroup.getChildCount(); ++i) { RadioButton btn = ((RadioButton) radioGroup.getChildAt(i)); btn.setButtonTintList(new ColorStateList( new int[][] { new int[] { -android.R.attr.state_enabled }, new int[] { android.R.attr.state_enabled } }, new int[] { Color.BLACK, ThemeHelper.getAccentColor() })); btn.invalidate();/*from ww w . j a va 2 s .c o m*/ } } }
From source file:org.gnucash.android.ui.report.ReportsOverviewFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(false);//w ww . ja v a 2 s . c o m mChart.setCenterTextSize(PieChartFragment.CENTER_TEXT_SIZE); mChart.setDescription(""); mChart.setDrawSliceText(false); Legend legend = mChart.getLegend(); legend.setEnabled(true); legend.setWordWrapEnabled(true); legend.setForm(LegendForm.CIRCLE); legend.setPosition(LegendPosition.RIGHT_OF_CHART_CENTER); legend.setTextSize(LEGEND_TEXT_SIZE); ColorStateList csl = new ColorStateList(new int[][] { new int[0] }, new int[] { getResources().getColor(R.color.account_green) }); setButtonTint(mPieChartButton, csl); csl = new ColorStateList(new int[][] { new int[0] }, new int[] { getResources().getColor(R.color.account_red) }); setButtonTint(mBarChartButton, csl); csl = new ColorStateList(new int[][] { new int[0] }, new int[] { getResources().getColor(R.color.account_blue) }); setButtonTint(mLineChartButton, csl); csl = new ColorStateList(new int[][] { new int[0] }, new int[] { getResources().getColor(R.color.account_purple) }); setButtonTint(mBalanceSheetButton, csl); }
From source file:com.ez.gallery.ucrop.view.widget.AspectRatioTextView.java
private void applyActiveColor(@ColorInt int activeColor) { if (mDotPaint != null) { mDotPaint.setColor(activeColor); }//w ww .ja v a 2 s . c o m ColorStateList textViewColorStateList = new ColorStateList( new int[][] { new int[] { android.R.attr.state_selected }, new int[] { 0 } }, new int[] { activeColor, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget) }); setTextColor(textViewColorStateList); }