Skip to content

附录:属性大全

CoorChice edited this page Feb 21, 2019 · 1 revision

对于 SuperTextView 所支持的绝大部分酷炫的效果,开发者均可以通过在 xml 布局文件中,通过简单的属性配置就能够实现。并且,借助 AndroidStudioPreview 插件,可以实时的预览这些效果。

以下是目前 SuperTextView 所支持的所有属性。

<SuperTextView

//设置圆角。会同时作用于填充和边框(如果边框存在的话)。
//如果要设置为圆形,只需要把该值设置为宽或长的1/2即可。
app:stv_corner="25dp"

//设置左上角圆角
app:stv_left_top_corner="true"

//设置右上角圆角
app:stv_right_top_corner="true"

//设置左下角圆角
app:stv_left_bottom_corner="true"

//设置右下角圆角
app:stv_right_bottom_corner="true"

//设置填充颜色
app:stv_solid="@color/red"

//设置边框颜色
app:stv_stroke_color="@color/black"

//设置边框的宽度。
app:stv_stroke_width="2dp"

//放置一个drawable在背景层上。默认居中显示。
//并且默认大小为SuperTextView的一半。
app:stv_state_drawable="@drawable/emoji"

//设置drawable的显示模式。可选值如下:
// left、top、right、bottom、center(默认值)、
//leftTop、rightTop、leftBottom、rightBottom、
//fill(充满整个SuperTextView,此时会使设置drawable的大小失效)
app:stv_state_drawable_mode="center"

//设置drawable的height
app:stv_state_drawable_height="30dp"

//设置drawable的width
app:stv_state_drawable_width="30dp"

//设置drawble相对于基础位置左边的距离
app:stv_state_drawable_padding_left="10dp"

//设置drawble相对于基础位置上边的距离
app:stv_state_drawable_padding_top="10dp"

// boolean类型。是否显示drawable。
//如果你想要设置的drawable显示出来,必须设置为true。
//当不想让它显示时,再设置为false即可。
app:stv_isShowState="true"

// 是否将state_drawable作为背景图
// 将state_drawable作为背景图可以让SuperTextView具备展示图片的能力
// 通过调节corner、stroke等属性,可以给图片设置圆角、边框等
app:stv_drawableAsBackground="true"

//放置一个drawable在背景层上。默认居中显示。
//并且默认大小为SuperTextView的一半。
app:stv_state_drawable2="@drawable/emoji"

//与state_drawable类似
app:stv_state_drawable2_mode="center"

//与state_drawable_height类似
app:stv_state_drawable2_height="30dp"

//与state_drawable_width类似
app:stv_state_drawable2_width="30dp"

//与state_drawable_padding_left类似
app:stv_state_drawable2_padding_left="10dp"

//与state_drawable_padding_top类似
app:stv_state_drawable2_padding_top="10dp"

//与isShowState类似
app:stv_isShow2State="true"

# 修改 drawable 的颜色
app:stv_state_drawable_tint="@color/gray"

# 修改 drawable2 的颜色
app:stv_state_drawable2_tint="@color/red"

# 修改 drawable 的旋转角度
app:stv_state_drawable_rotate="90"

# 修改 drawable2 的旋转角度
app:stv_state_drawable2_rotate="90"

//是否开启文字描边功能。
//注意,启用这个模式之后通过setTextColor()设置的颜色将会被覆盖。
//你需要通过text_fill_color来设置文字的颜色。
app:stv_text_stroke="true"

// 文字的描边颜色。默认为Color.BLACK。
app:stv_text_stroke_color="@color/black"

// 文字描边的宽度。
app:stv_text_stroke_width="1dp"

// 文字填充的颜色。默认为Color.BLACK。
app:stv_text_fill_color="@color/blue"

// boolean类型。是否启用Adjuster功能。
//具体干什么,需要在Java中为SuperTextView实现一个Adjuster。
//当你启用这个功能而没有实现自己的Adjuster时,
//SuperTextView会启用默认的Adjuster。它会按照一定的规则调整文字大小。
app:stv_autoAdjust="true"

// 必须设置为true才能启用渐变功能。这意味着你可以灵活的控制这一功能。
app:stv_shaderEnable="true"

// 设置起始颜色。
app:stv_shaderStartColor="@color/main_blue"

// 设置结尾颜色。
app:stv_shaderEndColor="@color/pink"

// 设置渐变模式。如上图可见,一共支持4中模式:
// topTopBottom, bottomToTop, leftToRight, rightToLeft
app:stv_shaderMode="rightToLeft"

// 设置按压时的背景色
app:stv_pressBgColor="@color/red"

// 设置按压时的文字颜色
app:stv_pressTextColor="@color/white"

// 修改 drawable 的颜色
app:stv_state_drawable_tint="@color/gray"

// 修改 drawable2 的颜色
app:stv_state_drawable2_tint="@color/red"

// 修改 drawable 的旋转角度
app:stv_state_drawable_rotate="90"

// 修改 drawable2 的旋转角度
app:stv_state_drawable2_rotate="90"

// 是否启用渐变色文字
app:stv_textShaderEnable="true"

// 设置文字的起始渐变色
app:stv_textShaderStartColor="@color/red"

// 设置文字的结束渐变色
app:stv_textShaderEndColor="@color/yellow"

// 设置文字的渐变的模式
// leftToRight:左 -> 右
// rightToLeft:右 -> 左
// topToBottom:上 -> 下
// bottomToTop:下 -> 上
app:stv_textShaderMode="leftToRight"


/>