当前位置: 首页>>代码示例>>Java>>正文


Java StateListDrawable.setEnterFadeDuration方法代码示例

本文整理汇总了Java中android.graphics.drawable.StateListDrawable.setEnterFadeDuration方法的典型用法代码示例。如果您正苦于以下问题:Java StateListDrawable.setEnterFadeDuration方法的具体用法?Java StateListDrawable.setEnterFadeDuration怎么用?Java StateListDrawable.setEnterFadeDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.drawable.StateListDrawable的用法示例。


在下文中一共展示了StateListDrawable.setEnterFadeDuration方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:FastAdapterUIUtils.java

示例2: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:DrawableUtils.java

示例3: 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;
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:77,代码来源:Coloring.java

示例4: 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;
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:69,代码来源:Coloring.java

示例5: 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;
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:64,代码来源:Coloring.java


注:本文中的android.graphics.drawable.StateListDrawable.setEnterFadeDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。