當前位置: 首頁>>代碼示例>>Java>>正文


Java StateSet類代碼示例

本文整理匯總了Java中android.util.StateSet的典型用法代碼示例。如果您正苦於以下問題:Java StateSet類的具體用法?Java StateSet怎麽用?Java StateSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StateSet類屬於android.util包,在下文中一共展示了StateSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update

import android.util.StateSet; //導入依賴的package包/類
private void update() {
    StateListDrawable background = new StateListDrawable();
    background.addState(new int[]{android.R.attr.state_pressed}, createDrawable(backgroundColorPressed, cornerColorPressed, cornerWidth, cornerRadius));
    background.addState(new int[]{-android.R.attr.state_enabled}, createDrawable(backgroundColorDisabled, cornerColorDisabled, cornerWidth, cornerRadius));
    background.addState(StateSet.WILD_CARD, createDrawable(backgroundColor, cornerColor, cornerWidth, cornerRadius));
    setBackground(background);

    setTextColor(new ColorStateList(
            new int[][]{
                    new int[]{android.R.attr.state_pressed},
                    new int[]{-android.R.attr.state_enabled},
                    new int[]{}
            },
            new int[]{
                    textColorPressed,
                    textColorDisabled,
                    textColor
            }
    ));
}
 
開發者ID:JMaroz,項目名稱:RoundButton,代碼行數:21,代碼來源:RoundButton.java

示例2: clearDrawableAnimation

import android.util.StateSet; //導入依賴的package包/類
/**
 * 清除View(etc:ListView) 拉至頂部或底部的橡皮筋效果
 */
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
開發者ID:nickyangjun,項目名稱:EasyEmoji,代碼行數:22,代碼來源:CommonUtil.java

示例3: clearDrawableAnimation

import android.util.StateSet; //導入依賴的package包/類
@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:20,代碼來源:AndroidUtilities.java

示例4: build

import android.util.StateSet; //導入依賴的package包/類
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
    GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();

    normal.setColor(mColor);
    selected.setColor(mColorPressed);

    if (mStroke > -1) {
        normal.setStroke(mStroke, mStrokeColor);
        selected.setStroke(mStroke, mStrokeColor);
    }

    if (mCorners > -1) {
        normal.setCornerRadius(mCorners);
        selected.setCornerRadius(mCorners);
    }

    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
    stateListDrawable.addState(StateSet.WILD_CARD, normal);

    return stateListDrawable;
}
 
開發者ID:OmarAliSaid,項目名稱:android-paypal-example,代碼行數:25,代碼來源:BadgeDrawableBuilder.java

示例5: extractStateSet

import android.util.StateSet; //導入依賴的package包/類
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 * @return An array of state_ attributes.
 */
protected int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) {
            break;
        } else if (stateResId == android.R.attr.drawable
                || stateResId == android.R.attr.id
                || stateResId == R.attr.drawableTint
                || stateResId == R.attr.drawableTintMode) {
            // Ignore attributes from StateListDrawableItem and
            // AnimatedStateListDrawableItem.
            continue;
        } else {
            states[j++] = attrs.getAttributeBooleanValue(i, false)
                    ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:30,代碼來源:DrawableUtils.java

示例6: extractStateSet

import android.util.StateSet; //導入依賴的package包/類
protected static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        switch (stateResId) {
            case 0:
                break;
            case android.R.attr.color:
            case android.R.attr.alpha:
                // Ignore attributes from StateListDrawableItem and
                // AnimatedStateListDrawableItem.
                continue;
            default:
                states[j++] = attrs.getAttributeBooleanValue(i, false)
                        ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:23,代碼來源:ColorStateListUtils.java

示例7: createStateListDrawable

import android.util.StateSet; //導入依賴的package包/類
public static StateListDrawable createStateListDrawable(Context context, String normalPicName, String pressedPicName) {
    Drawable normalDrawable;
    Drawable pressedDrawable;
    if (normalPicName.indexOf(".9") > -1) {
        normalDrawable = getNinePatchDrawable(context, normalPicName);
    } else {
        normalDrawable = getDrawable(context, normalPicName);
    }
    if (pressedPicName.indexOf(".9") > -1) {
        pressedDrawable = getNinePatchDrawable(context, pressedPicName);
    } else {
        pressedDrawable = getDrawable(context, pressedPicName);
    }
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{16842919}, pressedDrawable);
    drawable.addState(new int[]{16842913}, pressedDrawable);
    drawable.addState(new int[]{16842908}, pressedDrawable);
    drawable.addState(StateSet.WILD_CARD, normalDrawable);
    return drawable;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:21,代碼來源:ResourceManager.java

示例8: setState

import android.util.StateSet; //導入依賴的package包/類
/**
   * Called by View
   */
void setState(int[] state) {
  Tuple match = null;
  final int count = mTuples.size();
  for (int i = 0; i < count; i++) {
    final Tuple tuple = mTuples.get(i);
    if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
      match = tuple;
      break;
    }
  }
  if (match == mLastMatch) {
    return;
  }
  if (mLastMatch != null) {
    cancel();
  }

  mLastMatch = match;

  if (match != null) {
    start(match);
  }
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:27,代碼來源:StateListAnimator.java

示例9: onInflateTabView

import android.util.StateSet; //導入依賴的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;
}
 
開發者ID:michael-rapp,項目名稱:ChromeLikeTabSwitcher,代碼行數:17,代碼來源:TabletTabRecyclerAdapter.java

示例10: setState

import android.util.StateSet; //導入依賴的package包/類
void setState(int[] state) {
    Tuple match = null;
    int count = this.mTuples.size();
    for (int i = 0; i < count; i++) {
        Tuple tuple = (Tuple) this.mTuples.get(i);
        if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
            match = tuple;
            break;
        }
    }
    if (match != this.mLastMatch) {
        if (this.mLastMatch != null) {
            cancel();
        }
        this.mLastMatch = match;
        View view = (View) this.mViewRef.get();
        if (match != null && view != null && view.getVisibility() == 0) {
            start(match);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:22,代碼來源:StateListAnimator.java

示例11: initIdleStateDrawable

import android.util.StateSet; //導入依賴的package包/類
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());
}
 
開發者ID:fergus825,項目名稱:SmartOrnament,代碼行數:20,代碼來源:CircularProgressButton.java

示例12: setCircleButtonStateListDrawable

import android.util.StateSet; //導入依賴的package包/類
public void setCircleButtonStateListDrawable(View circleButton, int radius,int color) {
    WeakReference<Bitmap> imageNormal = new WeakReference<>(Bitmap.createBitmap(2 * radius, 2 * radius, Bitmap.Config.ARGB_8888));
    Canvas canvasNormal = new Canvas(imageNormal.get());
    Paint paintNormal = new Paint();
    paintNormal.setAntiAlias(true);
    paintNormal.setColor(color);
    canvasNormal.drawCircle(radius, radius, radius, paintNormal);
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(StateSet.WILD_CARD, new BitmapDrawable(circleButton.getContext().getResources(), imageNormal.get()));
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        circleButton.setBackground(stateListDrawable);
    } else {
        circleButton.setBackgroundDrawable(stateListDrawable);
    }

}
 
開發者ID:shenhuanet,項目名稱:OpenEyesReading-android,代碼行數:17,代碼來源:Util.java

示例13: extractStateSet

import android.util.StateSet; //導入依賴的package包/類
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 * @return An array of state_ attributes.
 */
static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) {
            break;
        } else if (stateResId == android.R.attr.drawable
                || stateResId == android.R.attr.id
                || stateResId == R.attr.drawableTint
                || stateResId == R.attr.drawableTintMode) {
            // Ignore attributes from StateListDrawableItem and
            // AnimatedStateListDrawableItem.
            continue;
        } else {
            states[j++] = attrs.getAttributeBooleanValue(i, false)
                    ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
開發者ID:Bilibili,項目名稱:MagicaSakura,代碼行數:30,代碼來源:DrawableUtils.java

示例14: setState

import android.util.StateSet; //導入依賴的package包/類
/**
 * Called by View
 */
void setState(int[] state) {
    Tuple match = null;
    final int count = mTuples.size();
    for (int i = 0; i < count; i++) {
        final Tuple tuple = mTuples.get(i);
        if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
            match = tuple;
            break;
        }
    }
    if (match == mLastMatch) {
        return;
    }
    if (mLastMatch != null) {
        cancel();
    }

    mLastMatch = match;

    View view = mViewRef.get();
    if (match != null && view != null && view.getVisibility() == View.VISIBLE ) {
        start(match);
    }
}
 
開發者ID:GigigoGreenLabs,項目名稱:permissionsModule,代碼行數:28,代碼來源:StateListAnimator.java

示例15: build

import android.util.StateSet; //導入依賴的package包/類
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable normal = (GradientDrawable) UIUtil.getCompatDrawable(ctx, R.drawable.action_item_badge);
    GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();

    normal.setColor(mColor);
    selected.setColor(mColorPressed);

    if (mCorners > -1) {
        normal.setCornerRadius(mCorners);
        selected.setCornerRadius(mCorners);
    }

    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
    stateListDrawable.addState(StateSet.WILD_CARD, normal);

    return stateListDrawable;
}
 
開發者ID:sathishmscict,項目名稱:AndroidActionItemBadge,代碼行數:20,代碼來源:BadgeDrawableBuilder.java


注:本文中的android.util.StateSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。