List of usage examples for android.content.res ColorStateList valueOf
@NonNull public static ColorStateList valueOf(@ColorInt int color)
From source file:com.finchuk.clock2.timepickers.Utils.java
/** * Sets the color on the {@code view}'s {@code selectableItemBackground} or the * borderless variant, whichever was set as the background. * @param view the view that should have its highlight color changed *///from ww w . j a va 2 s. co m public static void setColorControlHighlight(@NonNull View view, @ColorInt int color) { Drawable selectableItemBackground = view.getBackground(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && selectableItemBackground instanceof RippleDrawable) { ((RippleDrawable) selectableItemBackground).setColor(ColorStateList.valueOf(color)); } else { // Draws the color (src) onto the background (dest) *in the same plane*. // That means the color is not overlapping (i.e. on a higher z-plane, covering) // the background. That would be done with SRC_OVER. // The DrawableCompat tinting APIs *could* be a viable alternative, if you // call setTintMode(). Previous attempts using those APIs failed without // the tint mode. However, those APIs have the overhead of mutating and wrapping // the drawable. selectableItemBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); } }
From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java
/** * This function sets the colors of the scan screen (only if the experience contains colors). *///from ww w . j av a2 s . c o m public void setExperienceStyle() { if (this.experience != null) { if (this.experience.getBackgroundColor() != null || this.experience.getForegroundColor() != null) { if (this.experience.getBackgroundColor() != null) { View topFrame = findViewById(R.id.topView); View bottomFrame = findViewById(R.id.bottomView); int backgroundColor = Color.parseColor(this.experience.getBackgroundColor()); // If no transparency is set add default transparency to background: if (this.experience.getBackgroundColor().length() <= 7) backgroundColor &= 0xbbffffff; if (topFrame != null) topFrame.setBackgroundColor(backgroundColor); if (bottomFrame != null) bottomFrame.setBackgroundColor(backgroundColor); } if (this.experience.getForegroundColor() != null) { int foregroundColor = Color.parseColor(this.experience.getForegroundColor()); Toolbar v = (Toolbar) findViewById(R.id.toolbar); if (v != null) { v.setTitleTextColor(foregroundColor); // set back icon color: try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { v.getNavigationIcon().setTint(foregroundColor); } else { v.getNavigationIcon().setColorFilter( new PorterDuffColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY)); } } catch (NullPointerException e) { Log.w("", "Exception setting toolbar icon colour.", e); } } TextView scanScreenTextTitle = (TextView) findViewById(R.id.scanScreenTextTitle); if (scanScreenTextTitle != null) { scanScreenTextTitle.setTextColor(foregroundColor); } TextView scanScreenTextDesc = (TextView) findViewById(R.id.scanScreenTextDesc); if (scanScreenTextDesc != null) { scanScreenTextDesc.setTextColor(foregroundColor); } } } if (this.experience.getHighlightBackgroundColor() != null && this.experience.getHighlightForegroundColor() != null) { int foregroundColor = Color.parseColor(this.experience.getHighlightForegroundColor()); int backgroundColor = Color.parseColor(this.experience.getHighlightBackgroundColor()); Button b = (Button) findViewById(R.id.scan_event_button); if (b != null) { b.setTextColor(foregroundColor); b.setBackgroundColor(backgroundColor); } ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar); if (pb != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { pb.setIndeterminateTintList(ColorStateList.valueOf(backgroundColor)); } } if (this.experience.getScanScreenTextTitle() != null) { TextView textView = (TextView) findViewById(R.id.scanScreenTextTitle); if (textView != null) { textView.setVisibility(View.VISIBLE); textView.setText(this.experience.getScanScreenTextTitle()); } } if (this.experience.getScanScreenTextDesciption() != null) { TextView textView = (TextView) findViewById(R.id.scanScreenTextDesc); if (textView != null) { textView.setVisibility(View.VISIBLE); textView.setText(this.experience.getScanScreenTextDesciption()); } } } }
From source file:xyz.berial.textinputlayout.TextInputLayout.java
/** * //from w w w.j av a2 s. c om * * @param text */ private void updateCounterText(Editable text) { if (mCounterView != null) { final int currentLength = text.length(); mCounterView.setText(mResources.getString(R.string.counterMaxLength, currentLength, mCounterMaxLength)); if (currentLength == mCounterMaxLength + 1) { mCounterView.setTextAppearance(getContext(), mErrorTextAppearance); ViewCompat.setBackgroundTintList(mEditText, ColorStateList.valueOf(mResources.getColor(R.color.design_textinput_error_color))); } else if (currentLength == mCounterMaxLength) { if (!mErrorEnabled) { ViewCompat.setBackgroundTintList(mEditText, mFocusedTextColor); } mCounterView.setTextAppearance(getContext(), R.style.TextAppearance_Design_Counter); } } }
From source file:com.jpventura.xyzreader.ui.ArticleDetailFragment.java
@Override public void onGenerated(Palette palette) { int primaryColor = mRootView.getResources().getColor(R.color.primary); int primaryDarkColor = mRootView.getResources().getColor(R.color.primary_dark); int darkMutedColor = palette.getDarkMutedColor(primaryDarkColor); FloatingActionButton fab = (FloatingActionButton) mRootView.findViewById(R.id.share_fab); int lightVibrantColor = palette.getLightVibrantColor(getResources().getColor(android.R.color.white)); int lightMutedColor = palette.getLightVibrantColor(getResources().getColor(R.color.text_primary)); int vibrantColor = palette.getVibrantColor(getResources().getColor(R.color.accent)); fab.setRippleColor(lightVibrantColor); fab.setBackgroundTintList(ColorStateList.valueOf(vibrantColor)); mRootView.findViewById(R.id.meta_bar).setBackgroundColor(darkMutedColor); mTitleView.setTextColor(lightMutedColor); mBodyView.setLinkTextColor(vibrantColor); mMutedColor = palette.getDarkMutedColor(0xff333333); updateStatusBar();/* w w w.j ava 2 s . com*/ }
From source file:com.it520.activity.main.wight.SmartTabLayout.java
/** * Set the color used for styling the tab text. This will need to be called prior to calling * {@link #setViewPager(android.support.v4.view.ViewPager)} otherwise it will not get set * * @param color to use for tab text//from w w w . jav a 2 s . c o m */ public void setDefaultTabTextColor(int color) { tabViewTextColors = ColorStateList.valueOf(color); }
From source file:fr.cph.chicago.core.activity.StationActivity.java
@SuppressWarnings("unchecked") private void setUpStopLayouts(@NonNull final Map<TrainLine, List<Stop>> stopByLines) { Stream.of(stopByLines.entrySet()).forEach(entry -> { final TrainLine line = entry.getKey(); final List<Stop> stops = entry.getValue(); final View lineTitleView = getLayoutInflater().inflate(R.layout.activity_station_line_title, viewGroup, false);//from www . j av a2 s . c o m final TextView testView = (TextView) lineTitleView.findViewById(R.id.train_line_title); testView.setText(line.toStringWithLine()); testView.setBackgroundColor(line.getColor()); if (line == TrainLine.YELLOW) { testView.setBackgroundColor(yellowLine); } stopsView.addView(lineTitleView); Stream.of(stops).sorted().forEach(stop -> { final LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(paramsStop); final AppCompatCheckBox checkBox = new AppCompatCheckBox(this); checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> Preferences .saveTrainFilter(getApplicationContext(), stationId, line, stop.getDirection(), isChecked)); checkBox.setOnClickListener(v -> { if (checkBox.isChecked()) { trainArrivalObservable.subscribe(new SubscriberTrainArrival(this, swipeRefreshLayout)); } }); checkBox.setChecked( Preferences.getTrainFilter(getApplicationContext(), stationId, line, stop.getDirection())); checkBox.setTypeface(checkBox.getTypeface(), Typeface.BOLD); checkBox.setText(stop.getDirection().toString()); checkBox.setTextColor(grey); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { checkBox.setBackgroundTintList(ColorStateList.valueOf(line.getColor())); checkBox.setButtonTintList(ColorStateList.valueOf(line.getColor())); if (line == TrainLine.YELLOW) { checkBox.setBackgroundTintList(ColorStateList.valueOf(yellowLine)); checkBox.setButtonTintList(ColorStateList.valueOf(yellowLine)); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { checkBox.setForegroundTintList(ColorStateList.valueOf(line.getColor())); if (line == TrainLine.YELLOW) { checkBox.setForegroundTintList(ColorStateList.valueOf(yellowLine)); } } linearLayout.addView(checkBox); final LinearLayout arrivalTrainsLayout = new LinearLayout(this); arrivalTrainsLayout.setOrientation(LinearLayout.VERTICAL); arrivalTrainsLayout.setLayoutParams(paramsStop); int id = Util.generateViewId(); arrivalTrainsLayout.setId(id); ids.put(line.toString() + "_" + stop.getDirection().toString(), id); linearLayout.addView(arrivalTrainsLayout); stopsView.addView(linearLayout); }); }); }
From source file:com.josecalles.tistiq.mvp.view.MainActivity.java
private void setViewColors() { mFragmentContainer.setBackground(mBackgrounds.getDrawable(mSelectedTheme)); mToolbar.setBackgroundColor(mPrimaryColors.getColor(mSelectedTheme, 0)); mNavigationView.setBackgroundColor(mPrimaryDarkColors.getColor(mSelectedTheme, 0)); mNavigationView.setItemIconTintList(ColorStateList.valueOf(mAccents.getColor(mSelectedTheme, 0))); }
From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java
static private void initializeColorStateLists(Context ctx) { sColorStateNotPlaying = ColorStateList .valueOf(ctx.getResources().getColor(R.color.media_item_icon_not_playing)); sColorStatePlaying = ColorStateList.valueOf(ctx.getResources().getColor(R.color.media_item_icon_playing)); }
From source file:com.luseen.spacenavigation.SpaceNavigationView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); /**//from ww w . j a va 2 s .c o m * Restore current item index from savedInstance */ restoreCurrentItem(); /** * Trow exceptions if items size is greater than 4 or lesser than 2 */ if (spaceItems.size() < 2) { throw new NullPointerException("Your space item count must be greater than 1 ," + " your current items count is : " + spaceItems.size()); } if (spaceItems.size() > 4) { throw new IndexOutOfBoundsException( "Your items count maximum can be 4," + " your current items count is : " + spaceItems.size()); } /** * Get left or right content width */ contentWidth = (w - spaceNavigationHeight) / 2; /** * Removing all view for not being duplicated */ removeAllViews(); /** * Views initializations and customizing */ RelativeLayout mainContent = new RelativeLayout(context); RelativeLayout centreBackgroundView = new RelativeLayout(context); LinearLayout leftContent = new LinearLayout(context); LinearLayout rightContent = new LinearLayout(context); BezierView centreContent = buildBezierView(); FloatingActionButton fab = new FloatingActionButton(context); fab.setSize(FloatingActionButton.SIZE_NORMAL); fab.setBackgroundTintList(ColorStateList.valueOf(centreButtonColor)); fab.setImageResource(centreButtonIcon); fab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (spaceOnClickListener != null) spaceOnClickListener.onCentreButtonClick(); } }); /** * Set fab layout params */ LayoutParams fabParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); fabParams.addRule(RelativeLayout.CENTER_IN_PARENT); fabParams.setMargins(centreContentMargin, centreContentMargin, centreContentMargin, centreContentMargin); /** * Main content size */ LayoutParams mainContentParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mainContentHeight); mainContentParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Centre content size */ LayoutParams centreContentParams = new LayoutParams(centreContentWight, spaceNavigationHeight); centreContentParams.addRule(RelativeLayout.CENTER_HORIZONTAL); /** * Centre Background View content size and position */ LayoutParams centreBackgroundViewParams = new LayoutParams(centreContentWight, mainContentHeight); centreBackgroundViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL); centreBackgroundViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); /** * Left content size */ LayoutParams leftContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); leftContentParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); leftContentParams.addRule(LinearLayout.HORIZONTAL); /** * Right content size */ LayoutParams rightContentParams = new LayoutParams(contentWidth, ViewGroup.LayoutParams.MATCH_PARENT); rightContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rightContentParams.addRule(LinearLayout.HORIZONTAL); /** * Adding views background colors */ leftContent.setBackgroundColor(spaceBackgroundColor); rightContent.setBackgroundColor(spaceBackgroundColor); centreBackgroundView.setBackgroundColor(spaceBackgroundColor); /** * Adding view to centreContent */ centreContent.addView(fab, fabParams); /** * Adding views to mainContent */ mainContent.addView(leftContent, leftContentParams); mainContent.addView(rightContent, rightContentParams); /** * Adding views to mainView */ addView(centreBackgroundView, centreBackgroundViewParams); addView(centreContent, centreContentParams); addView(mainContent, mainContentParams); /** * Adding current space items to left and right content */ addSpaceItems(leftContent, rightContent); /** * Redraw main view to make subviews visible */ Utils.postRequestLayout(this); }
From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java
@Override public void onFailure(int errorCode, String errorMsg) { if (CommonUtils.getAPNType(ComicDetailsActivity.this) == CommonUtils.NONEWTWORK) { runOnUiThread(new Runnable() { @Override//from w ww.j a v a 2 s . c om public void run() { Toast.makeText(ComicDetailsActivity.this, Constants.NO_NETWORK, Toast.LENGTH_SHORT).show(); //??? if (mComic != null) { if (mComic.isMark() || mComic.isDownload()) { runOnUiThread(new Runnable() { @Override public void run() { updateViews(); } }); } } } }); } else { runOnUiThread(new Runnable() { @Override public void run() { mBinding.FABComicDetails.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.colorAccent))); Toast.makeText(ComicDetailsActivity.this, "?", Toast.LENGTH_SHORT).show(); } }); } }