android.graphics.drawable.StateListDrawable源码实例Demo

类android.graphics.drawable.StateListDrawable源码实例Demo

下面列出了怎么用android.graphics.drawable.StateListDrawable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ShareBox   文件: Label.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionDown() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{android.R.attr.state_pressed});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(true);
    }
 
源代码2 项目: clear-todolist   文件: FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
    drawable.addState(new int[]{}, createCircleDrawable(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;
}
 
源代码3 项目: material-calendarview   文件: DayView.java
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;
}
 
源代码4 项目: pixate-freestyle-android   文件: PXDrawableUtil.java
/**
 * Returns a {@link Map} that holds a mapping from the existing state-lists
 * in the background {@link Drawable}.
 * 
 * @param background A {@link Drawable} background (
 *            {@link StateListDrawable}).
 * @return A {@link Map}. An empty map in case the background
 *         <code>null</code>, or is not a {@link StateListDrawable}.
 */
public static Map<int[], Drawable> getExistingStates(Drawable background) {
    LinkedHashMap<int[], Drawable> map = new LinkedHashMap<int[], Drawable>();
    if (background instanceof StateListDrawable) {
        // Grab the existing states. Note that the API hides some of the
        // public functionality with the @hide tag, so we have to access
        // those through reflection...
        StateListDrawable stateList = (StateListDrawable) background;
        DrawableContainerState containerState = (DrawableContainerState) stateList
                .getConstantState();
        Drawable[] children = containerState.getChildren();
        try {
            // This method is public but hidden ("pending API council")
            Method method = stateList.getClass().getMethod("getStateSet", int.class);
            for (int i = 0; i < containerState.getChildCount(); i++) {
                Object state = method.invoke(stateList, i);
                if (state instanceof int[]) {
                    map.put((int[]) state, children[i]);
                }
            }
        } catch (Exception e) {
            PXLog.e(TAG, e, "Error getting the state set");
        }
    }
    return map;
}
 
源代码5 项目: QButton   文件: QButton.java
private void notifyChanges() {

        Float factor = 0.8f, factorStorke = 0.9f;

        if (!isEnable) {
            //handling for button disable state
            setAlpha(0.6f);
        }

        if (mStrokeColor == 0) {
            mStrokeColor = manipulateColor(mBackgroundColor, factorStorke);
        }

        Drawable pressed = getDrawable1(manipulateColor(mBackgroundColor, factor), mRadius);
        Drawable normal = getDrawable1(mBackgroundColor, mRadius);

        StateListDrawable states = new StateListDrawable();
        states.addState(new int[]{android.R.attr.state_pressed}, pressed);
        states.addState(new int[]{}, normal);
        setBackground(states);

    }
 
private void setSelectorDrawable(TypedArray typedArray, TypedArray selectorTa,
                                 StateListDrawable stateListDrawable, int attr, @AttrRes int functionId) throws Exception {
    int color = 0;
    Drawable resDrawable = null;

    //这里用try catch先判断是否是颜色而不是直接调用getDrawable,为了方便填入的是颜色时可以沿用其他属性,
    //否则如果是其他资源会覆盖app:corners_radius等其他shape属性设置的效果
    try {
        color = selectorTa.getColor(attr, 0);
        if (color == 0) {
            resDrawable = selectorTa.getDrawable(attr);
        }
    } catch (Exception e) {
        resDrawable = selectorTa.getDrawable(attr);
    }
    if (resDrawable == null && color != 0) {
        GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray);
        tmpDrawable.setColor(color);
        stateListDrawable.addState(new int[]{functionId}, tmpDrawable);
    } else {
        stateListDrawable.addState(new int[]{functionId}, resDrawable);
    }
}
 
源代码7 项目: StyleableDateTimePicker   文件: YearPickerView.java
/**
 * @param context
 */
public YearPickerView(Context context, DatePickerController controller) {
    super(context);
    mController = controller;
    mController.registerOnDateChangedListener(this);
    ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    setLayoutParams(frame);
    Resources res = context.getResources();
    mViewSize = res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height);
    mChildSize = res.getDimensionPixelOffset(R.dimen.year_label_height);
    setVerticalFadingEdgeEnabled(true);
    setFadingEdgeLength(mChildSize / 3);
    init(context);
    setOnItemClickListener(this);
    setSelector(new StateListDrawable());
    setDividerHeight(0);
    onDateChanged();
}
 
源代码8 项目: zhangshangwuda   文件: LessonsFragment.java
private StateListDrawable getStateSelector(String color) {
	StateListDrawable stalistDrawable = new StateListDrawable();
	// int normal = android.R.attr.state_empty;
	// int pressed = android.R.attr.state_pressed;
	// int focused = android.R.attr.state_focused;
	// int selected = android.R.attr.state_selected;
	ColorDrawable normalBG = new ColorDrawable(Color.parseColor(color));
	ColorDrawable pressedBG = new ColorDrawable(Color.parseColor("#AAAAAA"));
	int pressed = android.R.attr.state_pressed;
	int window_focused = android.R.attr.state_window_focused;
	int focused = android.R.attr.state_focused;
	int selected = android.R.attr.state_selected;
	stalistDrawable.addState(new int[] { pressed, window_focused },
			pressedBG);
	stalistDrawable.addState(new int[] { pressed, -focused }, pressedBG);
	stalistDrawable.addState(new int[] { selected }, pressedBG);
	stalistDrawable.addState(new int[] { focused }, pressedBG);
	// 没有任何状态时显示的图片,我们给它设置我空集合
	stalistDrawable.addState(new int[] {}, normalBG);
	return stalistDrawable;
}
 
@Override
@NonNull
public View getDropDownView(int position, @Nullable View convertView,
        @NonNull ViewGroup parent) {
    TextView textView = initTextView(position, convertView, parent);
    if (textView != convertView) {
        Drawable icon = createIcon();
        StateListDrawable statefulIcon = new StateListDrawable();
        statefulIcon.setBounds(icon.getBounds());
        statefulIcon.addState(ACTIVATED_STATE_SET, icon);
        TextViewCompat.setCompoundDrawablesRelative(
                textView, statefulIcon, null, null, null);
    }
    ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
    if (layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT) {
        layoutParams.height = spinner.getHeight() -
                spinner.getPaddingTop() - spinner.getPaddingBottom();
    }
    return textView;
}
 
源代码10 项目: YImagePicker   文件: PCornerUtils.java
/**
 * set btn selector with corner drawable for special position
 */
public static StateListDrawable btnSelector(float radius, int normalColor, int pressColor, int postion) {
    StateListDrawable bg = new StateListDrawable();
    Drawable normal = null;
    Drawable pressed = null;

    if (postion == 0) {// left btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
    } else if (postion == 1) {// right btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
    } else if (postion == -1) {// only one btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
    } else if (postion == -2) {// for material dialog
        normal = cornerDrawable(normalColor, radius);
        pressed = cornerDrawable(pressColor, radius);
    }

    bg.addState(new int[]{-android.R.attr.state_pressed}, normal);
    bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
    return bg;
}
 
源代码11 项目: timecat   文件: ThemeUtils.java
public static boolean containsNinePatch(Drawable drawable) {
    drawable = getWrapperDrawable(drawable);
    if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) {
        return true;
    } else if (drawable instanceof StateListDrawable) {
        final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
        //can't get containState from drawable which is containing DrawableWrapperDonut
        //https://code.google.com/p/android/issues/detail?id=169920
        if (containerState == null) {
            return true;
        }
        for (Drawable dr : containerState.getChildren()) {
            dr = getWrapperDrawable(dr);
            if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) {
                return true;
            }
        }
    }
    return false;
}
 
private void setSelectorDrawable(TypedArray typedArray, TypedArray selectorTa,
                                 StateListDrawable stateListDrawable, int attr, @AttrRes int functionId) throws Exception {
    int color = 0;
    Drawable resDrawable = null;

    //这里用try catch先判断是否是颜色而不是直接调用getDrawable,为了方便填入的是颜色时可以沿用其他属性,
    //否则如果是其他资源会覆盖app:corners_radius等其他shape属性设置的效果
    try {
        color = selectorTa.getColor(attr, 0);
        if (color == 0) {
            resDrawable = selectorTa.getDrawable(attr);
        }
    } catch (Exception e) {
        resDrawable = selectorTa.getDrawable(attr);
    }
    if (resDrawable == null && color != 0) {
        GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray);
        tmpDrawable.setColor(color);
        stateListDrawable.addState(new int[]{functionId}, tmpDrawable);
    } else {
        stateListDrawable.addState(new int[]{functionId}, resDrawable);
    }
}
 
源代码13 项目: FairEmail   文件: FastScrollerEx.java
public FastScrollerEx(RecyclerView recyclerView, StateListDrawable verticalThumbDrawable,
        Drawable verticalTrackDrawable, StateListDrawable horizontalThumbDrawable,
        Drawable horizontalTrackDrawable, int defaultWidth, int scrollbarMinimumRange,
        int margin) {
    mVerticalThumbDrawable = verticalThumbDrawable;
    mVerticalTrackDrawable = verticalTrackDrawable;
    mHorizontalThumbDrawable = horizontalThumbDrawable;
    mHorizontalTrackDrawable = horizontalTrackDrawable;
    mVerticalThumbWidth = Math.max(defaultWidth, verticalThumbDrawable.getIntrinsicWidth());
    mVerticalTrackWidth = Math.max(defaultWidth, verticalTrackDrawable.getIntrinsicWidth());
    mHorizontalThumbHeight = Math
        .max(defaultWidth, horizontalThumbDrawable.getIntrinsicWidth());
    mHorizontalTrackHeight = Math
        .max(defaultWidth, horizontalTrackDrawable.getIntrinsicWidth());
    mScrollbarMinimumRange = scrollbarMinimumRange;
    mMargin = margin;
    mVerticalThumbDrawable.setAlpha(SCROLLBAR_FULL_OPAQUE);
    mVerticalTrackDrawable.setAlpha(SCROLLBAR_FULL_OPAQUE);

    mShowHideAnimator.addListener(new AnimatorListener());
    mShowHideAnimator.addUpdateListener(new AnimatorUpdater());

    attachToRecyclerView(recyclerView);
}
 
@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;
}
 
源代码15 项目: UIWidget   文件: RadiusCompoundDelegate.java
/**
 * 设置CompoundButton的setButtonDrawable属性
 */
private void setButtonDrawable() {
    mButton = (CompoundButton) mView;
    if (mButtonDrawableSystemEnable) {
        return;
    }
    Log.i("setButtonDrawable", "id:" + mButton.getId() + ";mButtonDrawable:" + mButtonDrawable);
    if (mButtonDrawable == null
            && mButtonPressedDrawable == null
            && mButtonDisabledDrawable == null
            && mButtonSelectedDrawable == null
            && mButtonCheckedDrawable == null) {
        mButton.setButtonDrawable(null);
        return;
    }
    float radius = mButtonDrawableColorCircleEnable ?
            mButtonDrawableWidth + mButtonDrawableHeight / 2 : mButtonDrawableColorRadius;
    mStateButtonDrawable = new StateListDrawable();
    mStateButtonDrawable.addState(new int[]{mStateChecked}, getStateDrawable(mButtonCheckedDrawable, radius, mButtonDrawableWidth, mButtonDrawableHeight));
    mStateButtonDrawable.addState(new int[]{mStateSelected}, getStateDrawable(mButtonSelectedDrawable, radius, mButtonDrawableWidth, mButtonDrawableHeight));
    mStateButtonDrawable.addState(new int[]{mStatePressed}, getStateDrawable(mButtonPressedDrawable, radius, mButtonDrawableWidth, mButtonDrawableHeight));
    mStateButtonDrawable.addState(new int[]{mStateDisabled}, getStateDrawable(mButtonDisabledDrawable, radius, mButtonDrawableWidth, mButtonDrawableHeight));
    mStateButtonDrawable.addState(new int[]{}, getStateDrawable(mButtonDrawable, radius, mButtonDrawableWidth, mButtonDrawableHeight));
    DrawableUtil.setDrawableWidthHeight(mStateButtonDrawable, mButtonDrawableWidth, mButtonDrawableHeight);
    mButton.setButtonDrawable(mStateButtonDrawable);
}
 
源代码16 项目: clear-todolist   文件: Label.java
@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;
}
 
源代码17 项目: ShareBox   文件: FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
    drawable.addState(new int[]{}, createCircleDrawable(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;
}
 
源代码18 项目: MagicaSakura   文件: ThemeUtils.java
public static boolean containsNinePatch(Drawable drawable) {
    drawable = getWrapperDrawable(drawable);
    if (drawable instanceof NinePatchDrawable
            || drawable instanceof InsetDrawable
            || drawable instanceof LayerDrawable) {
        return true;
    } else if (drawable instanceof StateListDrawable) {
        final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
        //can't get containState from drawable which is containing DrawableWrapperDonut
        //https://code.google.com/p/android/issues/detail?id=169920
        if (containerState == null) {
            return true;
        }
        for (Drawable dr : containerState.getChildren()) {
            dr = getWrapperDrawable(dr);
            if (dr instanceof NinePatchDrawable
                    || dr instanceof InsetDrawable
                    || dr instanceof LayerDrawable) {
                return true;
            }
        }
    }
    return false;
}
 
源代码19 项目: SprintNBA   文件: CornerUtils.java
/**
 * set btn selector with corner drawable for special position
 */
public static StateListDrawable btnSelector(float radius, int normalColor, int pressColor, int postion) {
    StateListDrawable bg = new StateListDrawable();
    Drawable normal = null;
    Drawable pressed = null;

    if (postion == 0) {// left btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
    } else if (postion == 1) {// right btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
    } else if (postion == -1) {// only one btn
        normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
        pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
    } else if (postion == -2) {// for material dialog
        normal = cornerDrawable(normalColor, radius);
        pressed = cornerDrawable(pressColor, radius);
    }

    bg.addState(new int[]{-android.R.attr.state_pressed}, normal);
    bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
    return bg;
}
 
源代码20 项目: FirefoxReality   文件: CustomFastScroller.java
CustomFastScroller(RecyclerView recyclerView, StateListDrawable verticalThumbDrawable,
             Drawable verticalTrackDrawable, StateListDrawable horizontalThumbDrawable,
             Drawable horizontalTrackDrawable, int defaultWidth, int scrollbarMinimumRange,
             int margin, boolean alwaysVisible) {
    mVerticalThumbDrawable = verticalThumbDrawable;
    mVerticalTrackDrawable = verticalTrackDrawable;
    mHorizontalThumbDrawable = horizontalThumbDrawable;
    mHorizontalTrackDrawable = horizontalTrackDrawable;
    mVerticalThumbWidth = Math.max(defaultWidth, verticalThumbDrawable.getIntrinsicWidth());
    mVerticalTrackWidth = Math.max(defaultWidth, verticalTrackDrawable.getIntrinsicWidth());
    mHorizontalThumbHeight = Math
            .max(defaultWidth, horizontalThumbDrawable.getIntrinsicWidth());
    mHorizontalTrackHeight = Math
            .max(defaultWidth, horizontalTrackDrawable.getIntrinsicWidth());
    mDefaultWidth = defaultWidth;
    mScrollbarMinimumRange = scrollbarMinimumRange;
    mMargin = margin;
    mAlwaysVisible = alwaysVisible;
    mVerticalThumbDrawable.setAlpha(SCROLLBAR_FULL_OPAQUE);
    mVerticalTrackDrawable.setAlpha(SCROLLBAR_FULL_OPAQUE);

    mShowHideAnimator.addListener(new AnimatorListener());
    mShowHideAnimator.addUpdateListener(new AnimatorUpdater());

    attachToRecyclerView(recyclerView);
}
 
源代码21 项目: fingen   文件: TagView.java
private Drawable getSelector(Tag tag) {
	if (tag.background!=null)return tag.background;
	StateListDrawable states = new StateListDrawable();
	GradientDrawable gd_normal = new GradientDrawable();
	gd_normal.setColor(tag.layoutColor);
	gd_normal.setCornerRadius(tag.radius);
	if (tag.layoutBorderSize>0){
		gd_normal.setStroke(Utils.dipToPx(getContext(),tag.layoutBorderSize), tag.layoutBorderColor);
	}
	GradientDrawable gd_press = new GradientDrawable();
	gd_press.setColor(tag.layoutColorPress);
	gd_press.setCornerRadius(tag.radius);
	states.addState(new int[] { android.R.attr.state_pressed }, gd_press);
	//must add state_pressed first,or state_pressed will not take effect
	states.addState(new int[] {}, gd_normal);
	return states;
}
 
源代码22 项目: PersianDateRangePicker   文件: YearPickerView.java
/**
 * @param context
 */
public YearPickerView(Context context, DatePickerController controller) {
  super(context);
  mController = controller;
  mController.registerOnDateChangedListener(this);
  ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
    LayoutParams.WRAP_CONTENT);
  setLayoutParams(frame);
  Resources res = context.getResources();
  mViewSize = res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height);
  mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
  setVerticalFadingEdgeEnabled(true);
  setFadingEdgeLength(mChildSize / 3);
  init(context);
  setOnItemClickListener(this);
  setSelector(new StateListDrawable());
  setDividerHeight(0);
  onDateChanged();
}
 
源代码23 项目: AlarmOn   文件: YearPickerView.java
/**
 * @param context
 */
public YearPickerView(Context context, DatePickerController controller) {
    super(context);
    mController = controller;
    mController.registerOnDateChangedListener(this);
    ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    setLayoutParams(frame);
    Resources res = context.getResources();
    mViewSize = res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height);
    mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
    setVerticalFadingEdgeEnabled(true);
    setFadingEdgeLength(mChildSize / 3);
    init(context);
    setOnItemClickListener(this);
    setSelector(new StateListDrawable());
    setDividerHeight(0);
    onDateChanged();
}
 
源代码24 项目: ProgressButton   文件: CircularProgressButton.java
private void initIdleStateDrawable() {
    int colorNormal = getNormalColor(mIdleColorState);
    int colorPressed = getPressedColor(mIdleColorState);
    int colorFocused = getFocusedColor(mIdleColorState);
    int colorDisabled = getDisabledColor(mIdleColorState);
    if (background == null) {
        background = createDrawable(colorNormal);
    }

    StrokeGradientDrawable drawableDisabled = createDrawable(colorDisabled);
    StrokeGradientDrawable drawableFocused = createDrawable(colorFocused);
    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mIdleStateDrawable = new StateListDrawable();

    mIdleStateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed.getGradientDrawable());
    mIdleStateDrawable.addState(new int[]{android.R.attr.state_focused}, drawableFocused.getGradientDrawable());
    mIdleStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, drawableDisabled.getGradientDrawable());
    mIdleStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
 
源代码25 项目: UtilsLib   文件: SelectorUtil.java
/**
 * 根据map里面创建选择器
 *
 * @param states 封装了状态对应的Drawable对象的集合,状态选择器是有前后顺序的,所以请使用LinkedHashMap
 * @return map中的选择器
 */
public static StateListDrawable createSelectorByStates(LinkedHashMap<int[], Drawable> states) {
    //如果map里面的状态小于2个,就不能生成选择器
    if (null == states || states.size() < 2) {
        throw new IllegalStateException("You must make 2 state to create seletor!");
    }
    //创建选择器对象
    StateListDrawable stateListDrawable = new StateListDrawable();
    //遍历集合
    Set<Map.Entry<int[], Drawable>> set = states.entrySet();
    for (Map.Entry<int[], Drawable> next : set) {
        int[] state = next.getKey();
        LogUtil.e(null, state.length);
        Drawable drawable = next.getValue();
        //给选择器添加对应的状态
        stateListDrawable.addState(state, drawable);
    }
    return stateListDrawable;
}
 
源代码26 项目: ankihelper   文件: UiUtil.java
public static StateListDrawable createStateDrawable(@ColorInt int colorSelected,
                                                    @ColorInt int colorNormal) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[]{android.R.attr.state_selected}, new ColorDrawable(colorSelected));
    stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(colorNormal));
    return stateListDrawable;
}
 
源代码27 项目: a   文件: Selector.java
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;
}
 
源代码28 项目: SimpleNews   文件: ColorChooserDialog.java
private Drawable createSelector(int color, int darkColor) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(darkColor);

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[]{-android.R.attr.state_pressed}, coloredCircle);
    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, darkerCircle);
    return stateListDrawable;
}
 
源代码29 项目: APlayer   文件: CircleView.java
private Drawable createSelector(int color) {
  ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
  darkerCircle.getPaint().setColor(translucentColor(shiftColorUp(color)));
  StateListDrawable stateListDrawable = new StateListDrawable();
  stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, darkerCircle);
  return stateListDrawable;
}
 
源代码30 项目: letv   文件: ImageActivity.java
public void b(Button button) {
    Drawable stateListDrawable = new StateListDrawable();
    Drawable a = this.a.b("com.tencent.plus.gray_normal.png");
    Drawable a2 = this.a.b("com.tencent.plus.gray_down.png");
    Drawable a3 = this.a.b("com.tencent.plus.gray_disable.png");
    stateListDrawable.addState(View.PRESSED_ENABLED_STATE_SET, a2);
    stateListDrawable.addState(View.ENABLED_FOCUSED_STATE_SET, a);
    stateListDrawable.addState(View.ENABLED_STATE_SET, a);
    stateListDrawable.addState(View.FOCUSED_STATE_SET, a);
    stateListDrawable.addState(View.EMPTY_STATE_SET, a3);
    button.setBackgroundDrawable(stateListDrawable);
}
 
点击广告?(赏赐笔者)
 同包方法