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


Java StateListDrawable.getConstantState方法代码示例

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


在下文中一共展示了StateListDrawable.getConstantState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateMultiStateDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
 * Tests the {@link Coloring#createMultiStateDrawable(Drawable, Drawable, Drawable, boolean)} method.
 * <p>
 * Unfortunately some Drawable properties are not shadowed by Robolectric yet, so we can test only the basic stuff here.
 */
@Test
public final void testCreateMultiStateDrawable() {
    // noinspection deprecation - can't enforce Lollipop here
    final BitmapDrawable normal = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_on);
    assertNotNull("Normal drawable is null", normal);

    // noinspection deprecation - can't enforce Lollipop here
    final BitmapDrawable clicked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_off);
    assertNotNull("Clicked drawable is null", clicked);

    // noinspection deprecation - can't enforce Lollipop here
    final BitmapDrawable checked = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.star_off);
    assertNotNull("Checked drawable is null", checked);

    final StateListDrawable stateList = Coloring.createMultiStateDrawable(normal, clicked, checked, true);
    assertNotNull("Contrast state drawable is null", stateList);
    assertTrue("Contrast state drawable is not stateful", stateList.isStateful());
    final Drawable.ConstantState constantState = stateList.getConstantState();
    assertNotNull("Constant state is null", constantState);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:26,代码来源:ColoringTest.java

示例2: setColors

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
private void setColors(View view, int[] colors) {
    Drawable drawable = view.getBackground();
    if (drawable instanceof StateListDrawable) {
        StateListDrawable stateListDrawable = (StateListDrawable) drawable;
        DrawableContainerState drawableContainerState = (DrawableContainerState) stateListDrawable.getConstantState();
        if (drawableContainerState != null) {
            Drawable[] drawables = drawableContainerState.getChildren();
            for (int i = 0; i < colors.length; i++) if (drawables[i] instanceof GradientDrawable) ((GradientDrawable) drawables[i]).setColor(colors[i]);
        }
    } else Log.w(TAG, "Drawable of view must be StateListDrawable in WoWoStateListColorAnimation");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:WoWoStateListColorAnimation.java

示例3: testCreateStateList

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
 * Tests the {@link Coloring#createStateList(Context, int, int, int, boolean, int)} method.
 * <p>
 * Unfortunately {@link StateListDrawable#getCurrent()} is not shadowed by Robolectric yet.
 */
@Test
public final void testCreateStateList() {
    final int colorNormal = Color.WHITE;
    final int colorActive = Color.GRAY;
    final int colorFocused = Color.YELLOW;
    final StateListDrawable drawable = Coloring.createStateList(mActivityContext, colorNormal, colorActive, colorFocused, true, 0);
    assertNotNull("StateListDrawable is null", drawable);
    drawable.setState(new int[] {});
    assertTrue("StateListDrawable is not stateful", drawable.isStateful());
    final Drawable.ConstantState constantState = drawable.getConstantState();
    assertNotNull("Constant state is null", constantState);
    final Drawable currentState = drawable.getCurrent();
    assertNull("Robolectric started shadowing current state", currentState);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:20,代码来源:ColoringTest.java

示例4: testCreateContrastStateDrawable

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
/**
 * Tests the {@link Coloring#createContrastStateDrawable(Context, int, int, boolean, Drawable)} method.
 * <p>
 * Unfortunately some Drawable properties are not shadowed by Robolectric yet, so we can test only the basic stuff here.
 */
@Test
public final void testCreateContrastStateDrawable() {
    // noinspection deprecation - can't enforce Lollipop here
    final BitmapDrawable original = (BitmapDrawable) mActivityContext.getResources().getDrawable(android.R.drawable.btn_star_big_on);
    assertNotNull("Original drawable is null", original);

    final StateListDrawable stateList = Coloring.createContrastStateDrawable(mActivityContext, Color.WHITE, Color.BLACK, true, original);
    assertNotNull("Contrast state drawable is null", stateList);
    assertTrue("Contrast state drawable is not stateful", stateList.isStateful());
    final Drawable.ConstantState constantState = stateList.getConstantState();
    assertNotNull("Constant state is null", constantState);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:18,代码来源:ColoringTest.java

示例5: initialize

import android.graphics.drawable.StateListDrawable; //导入方法依赖的package包/类
public void initialize(Context context, AttributeSet attrs) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.setBackground(getResources().getDrawable(R.drawable.toggle_background, null));
        } else {
            this.setBackground(getResources().getDrawable(R.drawable.toggle_background));
        }

        StateListDrawable stateListDrawable = (StateListDrawable) this.getBackground();
        DrawableContainer.DrawableContainerState dcs = (DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState();
        Drawable[] drawableItems = dcs.getChildren();
        GradientDrawable unChecked = (GradientDrawable) drawableItems[0];
        GradientDrawable checked = (GradientDrawable) drawableItems[1];
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomToggleButton);

//        getting all the attributes values set from the typed array i.e from user
        int toggleOnColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedColor, Color.parseColor("#FF4081"));
        int toggleOffColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedColor, Color.parseColor("#FF4081"));
        float borderWidth = typedArray.getDimension(R.styleable.CustomToggleButton_borderWidth, 4.0f);
        float radius = typedArray.getDimension(R.styleable.CustomToggleButton_radius, 15.0f);
        int checkedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_checkedTextColor, getResources().getColor(R.color.CheckedTextColor));
        int uncheckedTextColor = typedArray.getColor(R.styleable.CustomToggleButton_uncheckedTextColor, getResources().getColor(R.color.uncheckedTextColor));
        Log.d(TAG, "initialize: " + borderWidth);
        ColorStateList colorStateList = new ColorStateList(
                new int[][]{
                        new int[]{android.R.attr.state_checked},
                        new int[]{-android.R.attr.state_checked}
                },
                new int[]{
                        checkedTextColor,
                        uncheckedTextColor
                }
        );

        this.setTextColor(colorStateList);


        checked.setStroke(Math.round(borderWidth), toggleOnColor);
        checked.setColor(toggleOnColor);
        checked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));

        unChecked.setStroke(Math.round(borderWidth), toggleOffColor);
        unChecked.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics()));


    }
 
开发者ID:Rishabhk07,项目名称:Custom-Toggle-Button,代码行数:47,代码来源:CustomToggleButton.java


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