/**
* 所有属性均可用代码动态实现
* 以下只是展示部分方法 可根据需求选择不同的方法
*/
superButton.setShapeType(SuperButton.RECTANGLE)
.setShapeCornersRadius(20)
.setShapeSolidColor(getResources().getColor(R.color.colorAccent))
.setShapeStrokeColor(getResources().getColor(R.color.colorPrimary))
.setShapeStrokeWidth(1)
.setShapeSrokeDashWidth(2)
.setShapeStrokeDashGap(5)
.setTextGravity(SuperButton.TEXT_GRAVITY_RIGHT)
.setShapeUseSelector(true)
.setShapeSelectorPressedColor(getResources().getColor(R.color.gray))
.setShapeSelectorNormalColor(getResources().getColor(R.color.red_btn))
.setShapeSelectorDisableColor(getResources().getColor(R.color.colorPrimary))
.setUseShape();
// TODO: 2017/8/12 动态设置切记需要在最后调用 setUseShape 才能对设置的参数生效
<com.allen.library.SuperButton
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:text="圆角边框"
stv:sCornersRadius="5dp"
stv:sStrokeColor="@color/colorAccent"
stv:sStrokeWidth="0.2dp" />
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<size
android:width="integer"
android:height="integer" />
<solid
android:color="color" />
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>
属性名 | 字段 | 描述 | 默认值 |
---|---|---|---|
sGravity | enum | 设置文字对其方式 center left right top bottom |
默认center |
sShapeType | enum | 设置Shape的类型 rectangle oval right line ring |
默认rectangle |
sSolidColor | color | 填充颜色 | 默认 |
sSelectorPressedColor | color | 按下时颜色 | 默认0x20000000 |
sSelectorDisableColor | color | 不可点击颜色 | 默认0x20000000 |
sSelectorNormalColor | color | 正常显示的颜色 | 默认0x20000000 |
sCornersRadius | dimension | shape的四个圆角半径 | 默认0dp |
sCornersTopLeftRadius | dimension | shape的左上圆角半径 | 默认0dp |
sCornersTopRightRadius | dimension | shape的右上圆角半径 | 默认0dp |
sCornersBottomLeftRadius | dimension | shape的左下圆角半径 | 默认0dp |
sCornersBottomRightRadius | dimension | shape的右下圆角半径 | 默认0dp |
sStrokeDashWidth | dimension | shape的虚线宽度 | 默认0dp |
sStrokeDashGap | dimension | shape的虚线间隙 | 默认0dp |
sStrokeWidth | dimension | shape的边框宽度 | 默认0dp |
sStrokeColor | color | shape的边框颜色 | 默认0x20000000 |
sSizeWidth | dimension | shape的SizeWidth | 默认0dp |
sSizeHeight | dimension | shape的SizeHeight | 默认0dp |
sGradientOrientation | enum | 设置渐变类型 TOP_BOTTOM TR_BL RIGHT_LEFT BR_TL BOTTOM_TOP BL_TR LEFT_RIGHT TL_BR |
默认rectangle |
sGradientType | enum | 设置渐变类型 linear radial sweep |
默认rectangle |
sGradientCenterX | float | shape的CenterX | 默认0f |
sGradientCenterY | float | shape的CenterY | 默认0f |
sGradientGradientRadius | dimension | shape的GradientRadius | 默认0dp |
sGradientStartColor | color | shape的StartColor | |
sGradientCenterColor | color | shape的CenterColor | |
sGradientEndColor | color | shape的EndColor | |
sGradientUseLevel | boolean | shape的UseLevel | 默认flase |
sUseSelector | boolean | 是否使用selector | 默认false |