本文整理汇总了Java中android.graphics.drawable.StateListDrawable.setExitFadeDuration方法的典型用法代码示例。如果您正苦于以下问题:Java StateListDrawable.setExitFadeDuration方法的具体用法?Java StateListDrawable.setExitFadeDuration怎么用?Java StateListDrawable.setExitFadeDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.StateListDrawable
的用法示例。
在下文中一共展示了StateListDrawable.setExitFadeDuration方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSelectableBackground
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
* helper to get the system default selectable background inclusive an active state
*
* @param ctx the context
* @param selected_color the selected color
* @param animate true if you want to fade over the states (only animates if API newer than Build.VERSION_CODES.HONEYCOMB)
* @return the StateListDrawable
*/
public static StateListDrawable getSelectableBackground(Context ctx, @ColorInt int selected_color, boolean animate) {
StateListDrawable states = new StateListDrawable();
ColorDrawable clrActive = new ColorDrawable(selected_color);
states.addState(new int[]{android.R.attr.state_selected}, clrActive);
states.addState(new int[]{}, ContextCompat.getDrawable(ctx, getSelectableBackground(ctx)));
//if possible we enable animating across states
if (animate) {
int duration = ctx.getResources().getInteger(android.R.integer.config_shortAnimTime);
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
示例2: generateBackground
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private static Drawable generateBackground(@Selection int selection, int color, int transparentColor, int fadeTime, Rect bounds) {
StateListDrawable drawable = new StateListDrawable();
drawable.setExitFadeDuration(fadeTime);
int resultColor = (selection == SELECTION_NORMAL || selection == SELECTION_FIRST || selection == SELECTION_LAST)
? color : transparentColor;
drawable.addState(new int[]{android.R.attr.state_checked}, generateCircleDrawable(resultColor));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.addState(new int[]{android.R.attr.state_pressed}, generateRippleDrawable(resultColor, bounds));
} else {
drawable.addState(new int[]{android.R.attr.state_pressed}, generateCircleDrawable(transparent(resultColor, 0.5f)));
}
drawable.addState(new int[]{}, generateCircleDrawable(Color.TRANSPARENT));
return drawable;
}
示例3: getStateListDrawable
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private static StateListDrawable getStateListDrawable(@ColorInt int normalColor,
@ColorInt int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_activated}, getColorDrawable(pressedColor));
states.addState(new int[]{}, getColorDrawable(normalColor));
// Animating across states.
// It seems item background is lost on scrolling out of the screen, 21 <= API <= 23
if (!Utils.hasLollipop() || Utils.hasNougat()) {
int duration = 200; //android.R.integer.config_shortAnimTime
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
示例4: 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;
}
示例5: 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;
}
示例6: setButton
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
static void setButton(@ColorInt int bgColor, @ColorInt int color, Button button, boolean colored) {
if (!colored) {
if (bgColor!=-1)
color = bgColor;
else
color = Color.parseColor("#ffffff");
}
int selectedColor = isColorLight(color) ?
ColorUtils.blendARGB(color, Color.parseColor("#000000"), 0.15f) :
ColorUtils.blendARGB(color, Color.parseColor("#FFFFFF"), 0.20f);
GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,
new int[]{selectedColor, selectedColor});
GradientDrawable drawable2 = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,
new int[]{color, color});
drawable.setCornerRadius(dpToPx(2));
drawable2.setCornerRadius(dpToPx(2));
StateListDrawable button1bg = new StateListDrawable();
button1bg.addState(new int[] {android.R.attr.state_pressed}, drawable);
button1bg.addState(new int[] {}, drawable2);
button1bg.setExitFadeDuration(250);
button.setBackgroundDrawable(button1bg);
}
示例7: 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;
}
示例8: createStateList
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
* Creates a new {@link StateListDrawable}. Colors that need to be provided are backgrounds for drawable states: "normal" (or "idle"),
* "clicked" (or "pressed") and "checked" (or "selected"). Optionally, a <i>fade</i> argument can be set to {@code false} to avoid the
* fading effect when the drawable animates.
*
* <b>Note</b>: Use {@link Color#TRANSPARENT} to set a transparent state.
*
* @param context Which context to use
* @param normal Color for the normal/idle state
* @param clicked Color for the clicked/pressed state
* @param checked Color for the checked/selected state (makes sense only for Honeycomb and later)
* @param shouldFade Set to {@code true} to enable the fading effect, {@code false} to disable it
* @param cornerRadius Set to round the corners on rectangular drawables, 0 to disable
* @return A {@link StateListDrawable} drawable object, new instance each time
*/
@NonNull
public static StateListDrawable createStateList(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
@ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius) {
// initialize state arrays (they're in arrays because you can use different drawables for reverse transitions..)
final int[] normalState = new int[] {};
final int[] clickedState = new int[] { android.R.attr.state_pressed };
final int[] checkedState = new int[] { android.R.attr.state_checked };
final int[] selectedState = new int[] { android.R.attr.state_selected };
final int[] focusedState = new int[] { android.R.attr.state_focused };
int[] activatedState = new int[] {};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activatedState = new int[] { android.R.attr.state_activated };
}
// normal state drawable
final Drawable normalDrawable = createColoredDrawable(normal, new Rect(0, 0, DEFAULT_BOUNDS, DEFAULT_BOUNDS));
if (normalDrawable instanceof GradientDrawable) {
((GradientDrawable) normalDrawable).setCornerRadius(cornerRadius);
}
// clicked state drawable
final Drawable clickedDrawable = createColoredDrawable(clicked, new Rect(0, 0, DEFAULT_BOUNDS, DEFAULT_BOUNDS));
if (clickedDrawable instanceof GradientDrawable) {
((GradientDrawable) clickedDrawable).setCornerRadius(cornerRadius);
}
// checked state drawable
final Drawable checkedDrawable = createColoredDrawable(checked, new Rect(0, 0, DEFAULT_BOUNDS, DEFAULT_BOUNDS));
if (checkedDrawable instanceof GradientDrawable) {
((GradientDrawable) checkedDrawable).setCornerRadius(cornerRadius);
}
// focused state drawable (same as normal, only lighter)
final Drawable focusedDrawable = createColoredDrawable(lightenColor(normal), new Rect(0, 0, DEFAULT_BOUNDS, DEFAULT_BOUNDS));
if (focusedDrawable instanceof GradientDrawable) {
((GradientDrawable) focusedDrawable).setCornerRadius(cornerRadius);
}
// prepare the state list (order of the states is extremely important!)
final StateListDrawable states = new StateListDrawable();
if (!shouldFade) {
// no fading, add all applicable states
states.addState(clickedState, clickedDrawable); // !
states.addState(selectedState, focusedDrawable); // reuse the focused drawable
states.addState(focusedState, focusedDrawable);
states.addState(checkedState, checkedDrawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
states.addState(activatedState, focusedDrawable);
}
states.addState(normalState, normalDrawable); // !
return states;
} else {
// fade enabled, add only normal and pressed states (Honeycomb bug..)
states.addState(clickedState, clickedDrawable); // !
states.addState(normalState, normalDrawable); // !
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// fading only works on Honeycomb and later..
states.setEnterFadeDuration(0);
states.setExitFadeDuration(DEFAULT_FADE_DURATION);
}
return states;
}
}
示例9: createContrastStateDrawable
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
* Creates a new {@link StateListDrawable} used for {@link android.widget.ImageView} icon coloring. The resulting state list's "pressed" icon color will be
* <b>contrasted</b> to the "pressed" color of the {@link android.widget.ImageView}'s background drawable.
* For example, since {@link android.widget.ImageButton} extends {@link android.widget.ImageView}, you can configure the ImageView's background to be black
* when "idle" and white when "clicked", and set a fully white "idle" icon. This means that, when you click the {@link android.widget.ImageView}, its
* background becomes white, making the white icon impossible to see. This method returns a drawable state list that will switch the icon color to black
* when pressed, making the icon visible even on a white background; the only thing you really need to provide here is the background color you used for
* the pressed state.
*
* @param context Which context to use
* @param normalColor Color normal/idle icon state to this color
* @param pressedBackColor Background color of the View that shows up when the View is pressed
* @param shouldFade Set to {@code true} if the state transition should have a fading effect
* @param original The "idle" state icon. This is the coloring base for all states
* @return The color state list that takes care of contrasted colors
*/
@NonNull
public static StateListDrawable createContrastStateDrawable(@NonNull final Context context, @ColorInt final int normalColor, @ColorInt final int
pressedBackColor,
final boolean shouldFade, @NonNull final Drawable original) {
// migrate to a static drawable
Drawable originalState = original;
if (originalState instanceof StateListDrawable) {
originalState = originalState.getCurrent();
}
// initialize state arrays (they're in arrays because you can use different colors for reverse transitions..)
final int[] normalState = new int[] {};
final int[] clickedState = new int[] { android.R.attr.state_pressed };
final int[] checkedState = new int[] { android.R.attr.state_checked };
final int[] selectedState = new int[] { android.R.attr.state_selected };
final int[] focusedState = new int[] { android.R.attr.state_focused };
int[] activatedState = new int[] {};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activatedState = new int[] { android.R.attr.state_activated };
}
final Drawable normalDrawable = colorDrawable(context, originalState, normalColor);
final Drawable clickedDrawable = colorDrawable(context, originalState, contrastColor(pressedBackColor));
final Drawable checkedDrawable = colorDrawable(context, originalState, contrastColor(pressedBackColor));
final Drawable focusedDrawable = colorDrawable(context, originalState, contrastColor(darkenColor(pressedBackColor)));
// prepare the state list (order of the states is extremely important!)
final StateListDrawable states = new StateListDrawable();
if (!shouldFade) {
// no fading, add all applicable states
states.addState(clickedState, clickedDrawable); // !
states.addState(selectedState, focusedDrawable); // reuse the focused drawable
states.addState(focusedState, focusedDrawable);
states.addState(checkedState, checkedDrawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
states.addState(activatedState, focusedDrawable);
}
states.addState(normalState, normalDrawable); // !
return states;
} else {
// fade enabled, add only normal and pressed states (Honeycomb bug..)
states.addState(clickedState, clickedDrawable); // !
states.addState(normalState, normalDrawable); // !
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// fading only works on Honeycomb and later..
states.setEnterFadeDuration(0);
states.setExitFadeDuration(DEFAULT_FADE_DURATION);
}
return states;
}
}
示例10: createMultiStateDrawable
import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
* Creates a new, multi-state {@link StateListDrawable} using the provided static drawables.
*
* @param normalDrawable Used for the normal/idle and focused states
* @param clickedDrawable Used for the clicked/pressed state
* @param checkedDrawable Used for the checked/selected and active states
* @param shouldFade Set to {@code true} if the state transition should have a fading effect
* @return A multi-state {@link StateListDrawable} consisting out of provided drawables, always a new instance
*/
@NonNull
public static StateListDrawable createMultiStateDrawable(@NonNull final Drawable normalDrawable, @NonNull final Drawable clickedDrawable,
@NonNull final Drawable checkedDrawable, final boolean shouldFade) {
// migrate to static drawables
Drawable normalState = normalDrawable;
if (normalState instanceof StateListDrawable) {
normalState = normalState.getCurrent();
}
Drawable clickedState = clickedDrawable;
if (clickedState instanceof StateListDrawable) {
clickedState = clickedState.getCurrent();
}
Drawable checkedState = checkedDrawable;
if (checkedState instanceof StateListDrawable) {
checkedState = checkedState.getCurrent();
}
// initialize state arrays (they're in arrays because you can use different colors for reverse transitions..)
final int[] normalStates = new int[] {};
final int[] clickedStates = new int[] { android.R.attr.state_pressed };
final int[] checkedStates = new int[] { android.R.attr.state_checked };
final int[] selectedStates = new int[] { android.R.attr.state_selected };
final int[] focusedStates = new int[] { android.R.attr.state_focused };
int[] activatedState = new int[] {};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activatedState = new int[] { android.R.attr.state_activated };
}
// prepare the state list (order of the states is extremely important!)
final StateListDrawable states = new StateListDrawable();
if (!shouldFade) {
// no fading, add all applicable states
states.addState(clickedStates, clickedState); // !
states.addState(selectedStates, checkedState);
states.addState(focusedStates, normalState);
states.addState(checkedStates, checkedState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
states.addState(activatedState, checkedState);
}
states.addState(normalStates, normalState); // !
return states;
} else {
// fade enabled, add only normal and pressed states (Honeycomb bug..)
states.addState(clickedStates, clickedState); // !
states.addState(normalStates, normalState); // !
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// fading only works on Honeycomb and later..
states.setEnterFadeDuration(0);
states.setExitFadeDuration(DEFAULT_FADE_DURATION);
}
return states;
}
}