本文整理匯總了Java中android.graphics.drawable.StateListDrawable.addState方法的典型用法代碼示例。如果您正苦於以下問題:Java StateListDrawable.addState方法的具體用法?Java StateListDrawable.addState怎麽用?Java StateListDrawable.addState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.StateListDrawable
的用法示例。
在下文中一共展示了StateListDrawable.addState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFillDrawable
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
drawable.addState(new int[]{}, createRectDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
示例2: onInflateTabView
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
@NonNull
@Override
protected final View onInflateTabView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup parent,
@NonNull final AbstractTabViewHolder viewHolder) {
View view = inflater.inflate(R.layout.tablet_tab, parent, false);
StateListDrawable backgroundDrawable = new StateListDrawable();
Drawable defaultDrawable = ContextCompat
.getDrawable(getModel().getContext(), R.drawable.tablet_tab_background);
Drawable selectedDrawable = ContextCompat
.getDrawable(getModel().getContext(), R.drawable.tablet_tab_background_selected);
backgroundDrawable.addState(new int[]{android.R.attr.state_selected}, selectedDrawable);
backgroundDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
ViewUtil.setBackground(view, backgroundDrawable);
return view;
}
示例3: generateRoundDrawable
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public static Drawable generateRoundDrawable(float radiiL, float radiiR, int pressColor, int defaultColor) {
//外環的圓角矩形
float[] outRadii = new float[]{radiiL, radiiL, radiiR, radiiR, radiiR, radiiR, radiiL, radiiL};//四個角的 圓角幅度,8個可以設置的值,每個角都有2個邊 2*4=8個
//與內環的距離
RectF inset = new RectF(0, 0, 0, 0);
//按下狀態
Shape roundRectShape = new RoundRectShape(outRadii, inset, null);//圓角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圓角shape
shopDrawablePress.getPaint().setColor(pressColor);//設置顏色
//正常狀態
Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, null);
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//狀態shape
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下狀態
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他狀態
return bgStateDrawable;
}
示例4: addItem
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public void addItem(@DrawableRes int ico) {
EmojiTabItemView itemView = new EmojiTabItemView(getContext());
itemView.setImageResource(ico);
if (mItemBackgroundRes == 0) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[]{android.R.attr.state_checked},
new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{android.R.attr.state_pressed},
new ColorDrawable(getResources().getColor(R.color.default_base_bg_press)));
stateListDrawable.addState(new int[]{}, new ColorDrawable(Color.TRANSPARENT));
itemView.setBackground(stateListDrawable);
} else {
itemView.setBackgroundResource(mItemBackgroundRes);
}
addView(itemView, -1, -1);
itemView.setOnClickListener(this);
}
示例5: setBgSelector
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public void setBgSelector() {
StateListDrawable bg = new StateListDrawable();
setDrawable(gd_background, backgroundColor, strokeColor);
bg.addState(new int[]{-android.R.attr.state_pressed}, gd_background);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {//16
setBackground(bg);
} else {
//noinspection deprecation
setBackgroundDrawable(bg);
}
}
示例6: makeSelector
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
private StateListDrawable makeSelector(int color) {
StateListDrawable res = new StateListDrawable();
res.setExitFadeDuration(150);
GradientDrawable pressed_drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[] {getLightenColor(color),getLightenColor(color)});
pressed_drawable.setCornerRadius(resources.getDimensionPixelSize(R.dimen.pdlg_corner_radius));
GradientDrawable default_drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,new int[] {color,color});
default_drawable.setCornerRadius(resources.getDimensionPixelSize(R.dimen.pdlg_corner_radius));
res.addState(new int[]{android.R.attr.state_pressed}, pressed_drawable);
res.addState(new int[]{}, default_drawable);
return res;
}
示例7: createFillDrawable
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
private StateListDrawable createFillDrawable(float strokeWidth) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled, strokeWidth));
drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed, strokeWidth));
drawable.addState(new int[] { }, createCircleDrawable(mColorNormal, strokeWidth));
return drawable;
}
示例8: create
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public StateListDrawable create() {
StateListDrawable selector = new StateListDrawable();
if (hasSetDisabledDrawable)
selector.addState(new int[]{-android.R.attr.state_enabled}, mDisabledDrawable);
if (hasSetPressedDrawable)
selector.addState(new int[]{android.R.attr.state_pressed}, mPressedDrawable);
if (hasSetSelectedDrawable)
selector.addState(new int[]{android.R.attr.state_selected}, mSelectedDrawable);
if (hasSetFocusedDrawable)
selector.addState(new int[]{android.R.attr.state_focused}, mFocusedDrawable);
selector.addState(new int[]{}, mDefaultDrawable);
return selector;
}
示例9: getRadioButtonSelector
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
/**
* 通過代碼配置一個selector XML對象 . . <br>
* @author liulongzhenhai 2012-8-1 下午5:27:28 <br>
* @param normal 沒有狀態
* @param selected 選擇狀態
* @param pressed 按下狀態
* @return 返回selector 的對象布局
*/
public static StateListDrawable getRadioButtonSelector(final Drawable normal, final Drawable selected,
final Drawable pressed) {
final StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, pressed);
drawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, normal);
drawable.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, pressed);
drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_enabled }, pressed);
drawable.addState(new int[] {}, normal);
return drawable;
}
示例10: getSelectableDrawableFor
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
@NonNull
public static Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new ColorDrawable(lightenOrDarken(color, 0.40D))
);
stateListDrawable.addState(
new int[]{android.R.attr.state_focused},
new ColorDrawable(lightenOrDarken(color, 0.80D))
);
stateListDrawable.addState(
new int[]{},
new ColorDrawable(color)
);
return stateListDrawable;
} else {
ColorStateList pressedColor = ColorStateList.valueOf(lightenOrDarken(color, 0.4D));
ColorDrawable defaultColor = new ColorDrawable(color);
ShapeDrawable shapeDrawable = (ShapeDrawable) getShapeWithColor(color);
Drawable rippleColor = getRippleColor(color);
return new RippleDrawable(
pressedColor,
shapeDrawable,
rippleColor
);
}
}
示例11: createFillDrawable
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
/**
* @param circleRect the defined rectangle
* @param alpha between 0 - 1
* @return StateListDrawable
*/
protected StateListDrawable createFillDrawable(RectF circleRect, float alpha) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_pressed}, createAlphaDrawble(circleRect, mColorPressed, alpha));
drawable.addState(new int[]{}, createAlphaDrawble(circleRect, mColorNormal, alpha));
return drawable;
}
示例12: generateStrokeDrawable
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public static Drawable generateStrokeDrawable(float radii, float borderWidth, int pressColor, int defaultColor, int disableColor) {
float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四個角的 圓角幅度,8個可以設置的值,每個角都有2個邊 2*4=8個
//與內環的距離
RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);
//按下狀態
Shape roundRectShape = new RoundRectShape(outRadii, inset, outRadii);//圓角背景
ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圓角shape
shopDrawablePress.getPaint().setColor(pressColor);//設置顏色
ShapeDrawable shopDrawableEnable = new ShapeDrawable(roundRectShape);
shopDrawableEnable.getPaint().setColor(disableColor);
//正常狀態
Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
shopDrawableNormal.getPaint().setColor(defaultColor);
StateListDrawable bgStateDrawable = new StateListDrawable();//狀態shape
bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawableEnable);//按下狀態
bgStateDrawable.addState(new int[]{android.R.attr.state_checked}, shopDrawablePress);//按下狀態
bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下狀態
bgStateDrawable.addState(new int[]{android.R.attr.state_focused}, shopDrawablePress);//焦點狀態
bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他狀態
return bgStateDrawable;
}
示例13: generateBackground
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
private static Drawable generateBackground(int color, int fadeTime) {
StateListDrawable drawable = new StateListDrawable();
drawable.setExitFadeDuration(fadeTime);
drawable.addState(new int[]{16842912}, generateCircleDrawable(color));
if (VERSION.SDK_INT >= 21) {
drawable.addState(new int[]{16842919}, generateRippleDrawable(color));
} else {
drawable.addState(new int[]{16842919}, generateCircleDrawable(color));
}
drawable.addState(new int[0], generateCircleDrawable(0));
return drawable;
}
示例14: selectorChecked
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
public static Drawable selectorChecked(Drawable normalDrawable, Drawable pressDrawable) {
StateListDrawable listDrawable = new StateListDrawable();//狀態shape
listDrawable.addState(new int[]{android.R.attr.state_pressed}, pressDrawable);//按下狀態
listDrawable.addState(new int[]{android.R.attr.state_checked}, pressDrawable);//按下狀態
listDrawable.addState(new int[]{}, normalDrawable);//其他狀態
return listDrawable;
}
示例15: generateBackground
import android.graphics.drawable.StateListDrawable; //導入方法依賴的package包/類
private static Drawable generateBackground(int color, int fadeTime, Rect bounds) {
StateListDrawable drawable = new StateListDrawable();
drawable.setExitFadeDuration(fadeTime);
drawable.addState(new int[]{android.R.attr.state_checked}, generateCircleDrawable(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.addState(new int[]{android.R.attr.state_pressed}, generateRippleDrawable(color, bounds));
} else {
drawable.addState(new int[]{android.R.attr.state_pressed}, generateCircleDrawable(color));
}
drawable.addState(new int[]{}, generateCircleDrawable(Color.TRANSPARENT));
return drawable;
}