下面列出了怎么用android.support.v7.widget.TintTypedArray的API类实例代码及写法,或者点击链接到github查看源代码。
public MyToolBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initview();
if (attrs != null) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.MyToolBar, defStyleAttr, 0);
showSearchView = a.getBoolean(R.styleable.MyToolBar_showSearchView, false);
left_button_icon = a.getDrawable(R.styleable.MyToolBar_leftButtonIcon);
right_button_icon = a.getDrawable(R.styleable.MyToolBar_rightButtonIcon);
title = a.getString(R.styleable.MyToolBar_myTitle);
a.recycle();
}
isShouw();
setContentInsetsRelative(10, 10);
initListener();
}
public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), attrs,
com.ljz.base.widget.R.styleable.SelectorInjection, defStyleAttr, 0);
Drawable[] drawables = mView.getCompoundDrawables();
try {
int leftColor = a.getColor(com.ljz.base.widget.R.styleable.SelectorInjection_drawableLeftTint, DEFAULT_COLOR);
int topColor = a.getColor(com.ljz.base.widget.R.styleable.SelectorInjection_drawableTopTint, DEFAULT_COLOR);
int rightColor = a.getColor(com.ljz.base.widget.R.styleable.SelectorInjection_drawableRightTint, DEFAULT_COLOR);
int bottomColor = a.getColor(com.ljz.base.widget.R.styleable.SelectorInjection_drawableBottomTint, DEFAULT_COLOR);
int[] colors = {leftColor, topColor, rightColor, bottomColor};
tintDrawable(drawables, colors);
} finally {
a.recycle();
}
}
public KyToolBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
final TintTypedArray a =
TintTypedArray.obtainStyledAttributes(getContext(), attrs, R.styleable.KyToolbar,
defStyleAttr, 0);
final boolean enableKyNavigationIcon =
a.getBoolean(R.styleable.KyToolbar_enableKyNavigationIcon, true);
final boolean enableKySearch = a.getBoolean(R.styleable.KyToolbar_enableKySearch, false);
final Drawable navIcon = a.getDrawable(R.styleable.KyToolbar_KyNavigationIcon);
final Drawable rightButtonIcon = a.getDrawable(R.styleable.KyToolbar_setRightButton);
final String rightText = a.getString(R.styleable.KyToolbar_setRightText);
setNavigationIcon(navIcon);
setRightButtonIcon(rightButtonIcon);
enableKyNavigation(enableKyNavigationIcon);
setRightTextView(rightText);
setEnabledSearch(enableKySearch);
a.recycle();
}
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), attrs,
TINT_ATTRS, defStyleAttr, 0);
mIndeterminateDrawableResId = a.getResourceId(0, INVALID_ID);
mProgressDrawableResId = a.getResourceId(1, INVALID_ID);
a.recycle();
applySkin();
}
public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), attrs,
R.styleable.SkinBackgroundHelper, defStyleAttr, 0);
try {
if (a.hasValue(R.styleable.SkinBackgroundHelper_android_background)) {
mBackgroundResId = a.getResourceId(
R.styleable.SkinBackgroundHelper_android_background, INVALID_ID);
}
} finally {
a.recycle();
}
applySkin();
}
public SkinCompatAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
TINT_ATTRS, defStyleAttr, 0);
if (a.hasValue(0)) {
mDropDownBackgroundResId = a.getResourceId(0, INVALID_ID);
}
a.recycle();
applyDropDownBackgroundResource();
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
mTextHelper = new SkinCompatTextHelper(this);
mTextHelper.loadFromAttributes(attrs, defStyleAttr);
}
public SkinCompatMultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
TINT_ATTRS, defStyleAttr, 0);
if (a.hasValue(0)) {
mDropDownBackgroundResId = a.getResourceId(0, INVALID_ID);
}
a.recycle();
applyDropDownBackgroundResource();
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
mTextHelper = new SkinCompatTextHelper(this);
mTextHelper.loadFromAttributes(attrs, defStyleAttr);
}
public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
final Context context = mView.getContext();
// First read the TextAppearance style id
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
R.styleable.SkinCompatTextHelper, defStyleAttr, 0);
final int ap = a.getResourceId(R.styleable.SkinCompatTextHelper_android_textAppearance, INVALID_ID);
SkinLog.d(TAG, "ap = " + ap);
a.recycle();
if (ap != INVALID_ID) {
a = TintTypedArray.obtainStyledAttributes(context, ap, R.styleable.SkinTextAppearance);
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColor)) {
mTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
SkinLog.d(TAG, "mTextColorResId = " + mTextColorResId);
}
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColorHint)) {
mTextColorHintResId = a.getResourceId(
R.styleable.SkinTextAppearance_android_textColorHint, INVALID_ID);
SkinLog.d(TAG, "mTextColorHintResId = " + mTextColorHintResId);
}
a.recycle();
}
// Now read the style's values
a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SkinTextAppearance,
defStyleAttr, 0);
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColor)) {
mTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
SkinLog.d(TAG, "mTextColorResId = " + mTextColorResId);
}
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColorHint)) {
mTextColorHintResId = a.getResourceId(
R.styleable.SkinTextAppearance_android_textColorHint, INVALID_ID);
SkinLog.d(TAG, "mTextColorHintResId = " + mTextColorHintResId);
}
a.recycle();
applySkin();
}
public void onSetTextAppearance(Context context, int resId) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context,
resId, R.styleable.SkinTextAppearance);
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColor)) {
mTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
SkinLog.d(TAG, "mTextColorResId = " + mTextColorResId);
}
if (a.hasValue(R.styleable.SkinTextAppearance_android_textColorHint)) {
mTextColorHintResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColorHint, INVALID_ID);
SkinLog.d(TAG, "mTextColorHintResId = " + mTextColorHintResId);
}
a.recycle();
applySkin();
}
@Override
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
super.loadFromAttributes(attrs, defStyleAttr);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), attrs,
R.styleable.AppCompatSeekBar, defStyleAttr, 0);
mThumbResId = a.getResourceId(R.styleable.AppCompatSeekBar_android_thumb, INVALID_ID);
// final Drawable drawable = a.getDrawableIfKnown(R.styleable.AppCompatSeekBar_android_thumb);
// if (drawable != null) {
// mView.setThumb(drawable);
// }
// mTickMarkResId = a.getResourceId(R.styleable.AppCompatSeekBar_tickMark, INVALID_ID);
// final Drawable tickMark = a.getDrawable(R.styleable.AppCompatSeekBar_tickMark);
// setTickMark(tickMark);
// if (a.hasValue(R.styleable.AppCompatSeekBar_tickMarkTintMode)) {
// mTickMarkTintMode = DrawableUtils.parseTintMode(a.getInt(
// R.styleable.AppCompatSeekBar_tickMarkTintMode, -1), mTickMarkTintMode);
// mHasTickMarkTintMode = true;
// }
// if (a.hasValue(R.styleable.AppCompatSeekBar_tickMarkTint)) {
// mTickMarkTintList = a.getColorStateList(R.styleable.AppCompatSeekBar_tickMarkTint);
// mHasTickMarkTint = true;
// }
a.recycle();
// applyTickMarkTint();
applySkin();
}
public SkinCompatToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.Toolbar, defStyleAttr, 0);
mNavigationIconResId = a.getResourceId(R.styleable.Toolbar_navigationIcon, INVALID_ID);
int titleAp = a.getResourceId(R.styleable.Toolbar_titleTextAppearance, INVALID_ID);
int subtitleAp = a.getResourceId(R.styleable.Toolbar_subtitleTextAppearance, INVALID_ID);
a.recycle();
if (titleAp != INVALID_ID) {
a = TintTypedArray.obtainStyledAttributes(context, titleAp, R.styleable.SkinTextAppearance);
mTitleTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
a.recycle();
}
if (subtitleAp != INVALID_ID) {
a = TintTypedArray.obtainStyledAttributes(context, subtitleAp, R.styleable.SkinTextAppearance);
mSubtitleTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
a.recycle();
}
a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.Toolbar, defStyleAttr, 0);
if (a.hasValue(R.styleable.Toolbar_titleTextColor)) {
mTitleTextColorResId = a.getResourceId(R.styleable.Toolbar_titleTextColor, INVALID_ID);
}
if (a.hasValue(R.styleable.Toolbar_subtitleTextColor)) {
mSubtitleTextColorResId = a.getResourceId(R.styleable.Toolbar_subtitleTextColor, INVALID_ID);
}
a.recycle();
applyTitleTextColor();
applySubtitleTextColor();
applyNavigationIcon();
}
public SkinCompatCheckedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
mTextHelper = new SkinCompatTextHelper(this);
mTextHelper.loadFromAttributes(attrs, defStyleAttr);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
TINT_ATTRS, defStyleAttr, 0);
mCheckMarkResId = a.getResourceId(0, INVALID_ID);
a.recycle();
applyCheckMark();
}
public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
TintTypedArray a = null;
try {
a = TintTypedArray.obtainStyledAttributes(mView.getContext(), attrs,
R.styleable.SkinCompatImageView, defStyleAttr, 0);
mSrcResId = a.getResourceId(R.styleable.SkinCompatImageView_android_src, -1);
} finally {
if (a != null) {
a.recycle();
}
}
applySkin();
}
public BottomNavigationViewInner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes(context, attrs,
android.support.design.R.styleable.BottomNavigationView,
defStyleAttr, android.support.design.R.style.Widget_Design_BottomNavigationView,
new int[]{android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceInactive,
android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceActive});
// clear if you don't have set item icon tint list
if (!a.hasValue(android.support.design.R.styleable.BottomNavigationView_itemIconTint)) {
clearIconTintColor();
}
a.recycle();
}
public BaseToolBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
initViews();
setContentInsetsRelative(0, 0);
if (attrs != null) {
TintTypedArray array = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.BaseToolBar, defStyleAttr, 0);
String leftText = array.getString(R.styleable.BaseToolBar_leftText);
String centerText = array.getString(R.styleable.BaseToolBar_centerText);
String rightText = array.getString(R.styleable.BaseToolBar_rightText);
Drawable leftIcon = array.getDrawable(R.styleable.BaseToolBar_leftIcon);
Drawable rightIcon = array.getDrawable(R.styleable.BaseToolBar_rightIcon);
Drawable leftrightIcon = array.getDrawable(R.styleable.BaseToolBar_leftrightIcon);
int leftSize = array.getInt(R.styleable.BaseToolBar_leftTextSize, DEFAULT_TEXT_SIZE);
int rightSize = array.getInt(R.styleable.BaseToolBar_rightTextSize, DEFAULT_TEXT_SIZE);
int centerSize = array.getInt(R.styleable.BaseToolBar_centerTextSize, DEFAULT_TEXT_SIZE);
Drawable leftIconBackground = array.getDrawable(R.styleable.BaseToolBar_leftIconBackground);
Drawable rightIconBackground = array.getDrawable(R.styleable.BaseToolBar_leftIconBackground);
setLeftText(leftText);
setCenterText(centerText);
setRightText(rightText);
setLeftIcon(leftIcon);
setRightIcon(rightIcon);
setLeftRightIcon(leftrightIcon);
setLeftTextSize(leftSize);
setRightTextSize(rightSize);
setCenterTextSize(centerSize);
setLeftIconBackground(leftIconBackground);
setRightIconBackground(rightIconBackground);
array.recycle();
}
}
public SkinCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) {
super(context, attrs, defStyleAttr, mode, popupTheme);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
R.styleable.Spinner, defStyleAttr, 0);
if (getPopupContext() != null) {
if (mode == MODE_THEME) {
if (Build.VERSION.SDK_INT >= 11) {
// If we're running on API v11+ we will try and read android:spinnerMode
TypedArray aa = null;
try {
aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE,
defStyleAttr, 0);
if (aa.hasValue(0)) {
mode = aa.getInt(0, MODE_DIALOG);
}
} catch (Exception e) {
Log.i(TAG, "Could not read android:spinnerMode", e);
} finally {
if (aa != null) {
aa.recycle();
}
}
} else {
// Else, we use a default mode of dropdown
mode = MODE_DROPDOWN;
}
}
if (mode == MODE_DROPDOWN) {
final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(
getPopupContext(), attrs, R.styleable.Spinner, defStyleAttr, 0);
mPopupBackgroundResId = pa.getResourceId(R.styleable.Spinner_android_popupBackground, INVALID_ID);
pa.recycle();
}
}
a.recycle();
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
}
public NumberAddSubView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mInflater = LayoutInflater.from(context);
initView();
if (attrs != null) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.NumberAddSubView, defStyleAttr, 0);
int val = a.getInt(R.styleable.NumberAddSubView_value, 0);
setValue(val);
int maxVal = a.getInt(R.styleable.NumberAddSubView_maxValue, 0);
if (maxVal != 0)
setMaxValue(maxVal);
int minVal = a.getInt(R.styleable.NumberAddSubView_minValue, 0);
setMinValue(minVal);
Drawable etBackground = a.getDrawable(R.styleable.NumberAddSubView_editBackground);
if (etBackground != null)
setEditTextBackground(etBackground);
Drawable buttonAddBackground = a.getDrawable(R.styleable
.NumberAddSubView_buttonAddBackgroud);
if (buttonAddBackground != null)
setButtonAddBackgroud(buttonAddBackground);
Drawable buttonSubBackground = a.getDrawable(R.styleable
.NumberAddSubView_buttonSubBackgroud);
if (buttonSubBackground != null)
setButtonSubBackgroud(buttonSubBackground);
a.recycle();
}
}
public EnjoyshopToolBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context=context;
initView();
setContentInsetsRelative(10, 10);
if (attrs != null) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.EnjoyshopToolBar, defStyleAttr, 0);
final Drawable rightIcon = a.getDrawable(R.styleable.EnjoyshopToolBar_rightButtonIcon);
if (rightIcon != null) {
setRightButtonIcon(rightIcon);
}
boolean isShowSearchView = a.getBoolean(R.styleable.EnjoyshopToolBar_isShowSearchView,
false);
if (isShowSearchView) {
showSearchView();
hideTitleView();
}
CharSequence rightButtonText = a.getText(R.styleable.EnjoyshopToolBar_rightButtonText);
if (rightButtonText != null) {
setRightButtonText(rightButtonText);
}
boolean isShowLeft = a.getBoolean(R.styleable.EnjoyshopToolBar_isShowLeftIcon, false);
if (isShowLeft) {
setLeftIcon();
}else{
mLeftButton.setVisibility(GONE);
}
a.recycle();
}
}
@SuppressLint("RestrictedApi")
public CnToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
// toolbar两边边距
setContentInsetsRelative(10,10);
if(attrs !=null) {
@SuppressLint("RestrictedApi") final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.CnToolbar, defStyleAttr, 0);
@SuppressLint("RestrictedApi") final Drawable rightIcon = a.getDrawable(R.styleable.CnToolbar_rightButtonIcon);
if (rightIcon != null) {
//setNavigationIcon(navIcon);
setRightButtonIcon(rightIcon);
}
@SuppressLint("RestrictedApi") boolean isShowSearchView = a.getBoolean(R.styleable.CnToolbar_isShowSearchView,false);
if(isShowSearchView){
showSearchView();
hideTitleView();
}
a.recycle();
}
}
@SuppressLint("RestrictedApi")
public NumberAddSubView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mInflater = LayoutInflater.from(context);
initView();
if(attrs !=null){
@SuppressLint("RestrictedApi") final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.NumberAddSubView, defStyleAttr, 0);
@SuppressLint("RestrictedApi") int val = a.getInt(R.styleable.NumberAddSubView_value,0);
setValue(val);
@SuppressLint("RestrictedApi") int maxVal = a.getInt(R.styleable.NumberAddSubView_maxValue,0);
if(maxVal!=0)
setMaxValue(maxVal);
@SuppressLint("RestrictedApi") int minVal = a.getInt(R.styleable.NumberAddSubView_minValue,0);
setMinValue(minVal);
@SuppressLint("RestrictedApi") Drawable etBackground = a.getDrawable(R.styleable.NumberAddSubView_editBackground);
if(etBackground!=null)
setEditTextBackground(etBackground);
@SuppressLint("RestrictedApi") Drawable buttonAddBackground = a.getDrawable(R.styleable.NumberAddSubView_buttonAddBackgroud);
if(buttonAddBackground!=null)
setButtonAddBackgroud(buttonAddBackground);
@SuppressLint("RestrictedApi") Drawable buttonSubBackground = a.getDrawable(R.styleable.NumberAddSubView_buttonSubBackgroud);
if(buttonSubBackground!=null)
setButtonSubBackgroud(buttonSubBackground);
a.recycle();
}
}
@SuppressLint("RestrictedApi")
public CNiaoToolBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
setContentInsetsRelative(10,10);
if(attrs !=null) {
@SuppressLint("RestrictedApi") final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
R.styleable.CNiaoToolBar, defStyleAttr, 0);
@SuppressLint("RestrictedApi") final Drawable rightIcon = a.getDrawable(R.styleable.CNiaoToolBar_rcightButtonIcon);
if (rightIcon != null) {
//setNavigationIcon(navIcon);
setRightButtonIcon(rightIcon);
}
@SuppressLint("RestrictedApi") boolean isShowSearchView = a.getBoolean(R.styleable.CNiaoToolBar_icsShowSearchView,false);
if(isShowSearchView){
showSearchView();
hideTitleView();
}
@SuppressLint("RestrictedApi") CharSequence rightButtonText = a.getText(R.styleable.CNiaoToolBar_rcightButtonText);
if(rightButtonText !=null){
setRightButtonText(rightButtonText);
}
a.recycle();
}
}