本文整理汇总了Java中android.support.v4.view.ViewCompat.setBackgroundTintList方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.setBackgroundTintList方法的具体用法?Java ViewCompat.setBackgroundTintList怎么用?Java ViewCompat.setBackgroundTintList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.setBackgroundTintList方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setEditTextDisabled
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private static void setEditTextDisabled(EditText editText) {
editText.setInputType(InputType.TYPE_NULL);
editText.setTextIsSelectable(true);
editText.setKeyListener(null);
editText.setBackgroundResource(R.drawable.edit_text_readonly);
int color = StyledAttributesHelper.getColor(editText.getContext(), android.R.attr.textColorSecondary, 0);
ViewCompat.setBackgroundTintList(editText, ColorStateList.valueOf(color));
((ViewGroup) editText.getParent()).setAddStatesFromChildren(false);
}
示例2: setBackgroundActiveColor
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void setBackgroundActiveColor(View editText, int accentColor) {
if (editText.getBackground() == null)
return;
int normalColor = StyledAttributesHelper.getColor(editText.getContext(),
R.attr.colorControlNormal, 0);
int disabledColor = ColorUtils.setAlphaComponent(normalColor, (int) (255.f *
StyledAttributesHelper.getFloat(editText.getContext(), android.R.attr.disabledAlpha, 1.f)));
int[][] states = new int[][]{
new int[]{-android.R.attr.state_enabled},
new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused},
new int[]{}
};
int[] colors = new int[]{
disabledColor,
normalColor,
accentColor
};
ColorStateList list = new ColorStateList(states, colors);
editText.setBackground(new ColorFilterWorkaroundDrawable(editText.getBackground()));
ViewCompat.setBackgroundTintList(editText, list);
}
示例3: loadFromAttributes
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
TypedArray a = this.mView.getContext().obtainStyledAttributes(attrs, R.styleable.ViewBackgroundHelper, defStyleAttr, 0);
try {
if (a.hasValue(R.styleable.ViewBackgroundHelper_android_background)) {
ColorStateList tint = this.mDrawableManager.getTintList(this.mView.getContext(), a.getResourceId(R.styleable.ViewBackgroundHelper_android_background, -1));
if (tint != null) {
setInternalBackgroundTint(tint);
}
}
if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTint)) {
ViewCompat.setBackgroundTintList(this.mView, a.getColorStateList(R.styleable.ViewBackgroundHelper_backgroundTint));
}
if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTintMode)) {
ViewCompat.setBackgroundTintMode(this.mView, DrawableUtils.parseTintMode(a.getInt(R.styleable.ViewBackgroundHelper_backgroundTintMode, -1), null));
}
a.recycle();
} catch (Throwable th) {
a.recycle();
}
}
示例4: setTint
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) {
final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{
new int[]{-android.R.attr.state_enabled},
new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused},
new int[]{}
}, new int[]{
ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light),
ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
color
});
if (editText instanceof TintableBackgroundView) {
ViewCompat.setBackgroundTintList(editText, editTextColorStateList);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
editText.setBackgroundTintList(editTextColorStateList);
}
setCursorTint(editText, color);
}
示例5: setFilterButtonState
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void setFilterButtonState(boolean unread_state, boolean short_state, boolean long_state) {
ViewCompat.setBackgroundTintList(findViewById(R.id.button_filter_unread),
ContextCompat.getColorStateList(this,
unread_state ? R.color.colorFilterButtonOn : R.color.colorFilterButtonOff));
ViewCompat.setBackgroundTintList(findViewById(R.id.button_filter_short),
ContextCompat.getColorStateList(this,
short_state ? R.color.colorFilterButtonOn : R.color.colorFilterButtonOff));
ViewCompat.setBackgroundTintList(findViewById(R.id.button_filter_long),
ContextCompat.getColorStateList(this,
long_state ? R.color.colorFilterButtonOn : R.color.colorFilterButtonOff));
}
示例6: render
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void render(@Nullable final SearchSuggestionRVItem item,
@Nullable final OnClickListener listener) {
if (!hasContext() || item == null) {
return;
}
mItem = item;
if (listener != null) {
mListener = listener;
}
mSuggestionField.setText(item.getSuggestion());
if (mSuggestionField instanceof TintableBackgroundView) {
// "AppCompatTextView" and "com.android.support:appcompat-v7" are used, tint all states
ViewCompat.setBackgroundTintList(mSuggestionField,
new ColorStateList(STATES, new int[]{
AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
return;
}
// "com.android.support:appcompat-v7" is likely not being used, and thus "TextView" is used
Drawable background = mSuggestionField.getBackground();
if (background instanceof TintAwareDrawable) {
// tint all states of the given drawable
DrawableCompat.setTintList(background,
new ColorStateList(STATES, new int[]{
AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
return;
}
// last option, tint only the background individually
AbstractDrawableUtils.setDrawableTint(getContext(), background, item.getPlaceholder());
}
示例7: setupBackground
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void setupBackground(View view, AttributeSet attrs) {
StyledAttributesHelper r = StyledAttributesHelper.obtainStyledAttributes(view.getContext(), attrs, ATTRS_BG);
int bgResId = r.getResourceId(android.R.attr.background, 0);
if (bgResId == R.color.colorPrimary)
view.setBackgroundColor(ThemeHelper.getPrimaryColor(view.getContext()));
else if (bgResId == R.color.colorAccent)
view.setBackgroundColor(ThemeHelper.getAccentColor(view.getContext()));
else if (bgResId == R.drawable.colored_button)
ViewCompat.setBackgroundTintList(view, createColoredButtonColorStateList(view.getContext()));
r.recycle();
}
示例8: tint
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* Tint the button
*
* @param button the button
* @param color the color
*/
public static void tint(@NonNull Button button, @ColorInt int color) {
ColorStateList sl = new ColorStateList(new int[][]{
new int[]{}
}, new int[]{
color
});
ViewCompat.setBackgroundTintList(button, sl);
}
示例9: onCreate
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
setDrawUnderStatusbar(true);
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
mDisposable = new CompositeDisposable();
setBottomBarVisibility(View.GONE);
ViewUtil.setStatusBarHeight(this, statusBar);
mGenre = getIntent().getExtras().getParcelable(EXTRA_GENRE_ID);
mPresenter = new GenreDetailsPresenter(Injection.provideRepository(this),
this,
mGenre.id);
setUpToolBar();
setupRecyclerView();
int themeColor = ThemeStore.accentColor(this);
ViewCompat.setBackgroundTintList(playSongs, ColorStateList.valueOf(themeColor));
shuffleSongs.setTextColor(themeColor);
}