Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Repository files navigation

ShapeButton

A custom Android button

English | 简体中文

NO LONGER MAINTAINED

I won't add any new features further.

Note:I recommend that you use VastTools, which provides ShapeAndStateUtils that can meet most of your needs.

Preview

How to

Add it in your root build.gradle at the end of repositories

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Add the dependency

dependencies {
implementation 'com.github.SakurajimaMaii:ShapeButton:0.0.5'
}

Button shape currently supported

  • Circular/Oval Button
  • Rectangle Button
  • Rounded Rectangle Button
  • Any rounded rectangle button

The four click states currently supported

  • Default (normal)
  • Click or touch (pressed)
  • Focused (focused)
  • Unable(unable)

Quick use

Set in XML

<com.gcode.widget.ShapeButton
android:id="@+id/button"android:layout_margin="10dp"android:layout_width="wrap_content"android:layout_height="wrap_content" />

Attribute setting

Here is a Kotlin way.

button4.apply {
setButtonShapeType(ShapeButtonShapeType.ANY_ROUNDED_RECT_SHAPE)
setAnyRoundedRectCornerRadius(10f,0f,20f,0f)
setIsSolid(true)
setIsSolidColorGradient(true)
setGradientDirectionType(ShapeButtonGradientType.LINEAR_GRADIENT)
setSolidColorGradient(
ContextCompat.getColor(context, R.color.red),
ContextCompat.getColor(context, R.color.design_default_color_primary_dark),
ContextCompat.getColor(context, R.color.design_default_color_primary_variant)
)
setStrokeWidth(10f)
setRectButtonWidth(500f)
setRectButtonHeight(300f)
setBgColorStateList(
ContextCompat.getColor(context, R.color.palevioletred),
ContextCompat.getColor(context, R.color.blue),
ContextCompat.getColor(context, R.color.mediumvioletred),
ContextCompat.getColor(context, R.color.red),
)
setStrokeColorStateList(
ContextCompat.getColor(context, R.color.yellow),
ContextCompat.getColor(context, R.color.greenyellow),
ContextCompat.getColor(context, R.color.orange),
ContextCompat.getColor(context, R.color.darkgrey),
)
create()
}

Finally, you must call the create() method, otherwise it will not take effect.

Attribute

Attribute nameTypeDescriptionDefault value
button_shapedimensionButton shapeoval_shape
rect_shape
rounded_rect_shape
any_rounded_rect_shape
button_rect_widthdimensionRectangular button width
button_rect_heightdimensionRectangular button height
button_oval_radiusdimensionOval button radius
button_rounded_rect_corner_radiusdimensionRounded radius of rounded rectangular button
button_left_top_corner_radiusdimensionLT corner radii of any rounded rectangular button
button_left_bottom_corner_radiusdimensionLB corner radii of any rounded rectangular button
button_right_top_corner_radiusdimensionRT corner radii of any rounded rectangular button
button_right_bottom_corner_radiusdimensionRB corner radii of any rounded rectangular button
button_is_solidbooleantrue is button solid,false otherwisetrue
false
button_is_solid_color_gradientbooleantrue is solid color gradient,false otherwisetrue
false
button_start_solid_colorcolorStart solid color
button_center_solid_colorcolorCenter solid color
button_end_solid_colorcolorEnd solid color
button_gradient_typedimensionGradient typelinear_gradient
radial_gradient
sweep_shape
button_gradient_orientationdimensionGradient orientation
button_gradient_radiusdimensionGradient radius
button_stroke_widthdimensionStroke width
button_normal_bg_colorcolorDefault button background color
button_pressed_bg_colorcolorButton background color when button is pressed.
button_focused_bg_colorcolorButton background color when button is focused.
button_unable_bg_colorcolorButton background color when button is unable.
button_normal_stroke_colorcolorDefault button stroke color.
button_pressed_stroke_colorcolorButton stroke color when button is pressed.
button_focused_stroke_colorcolorButton stroke color when button is focused.
button_unable_stroke_colorcolorButton stroke color when button is unable.

Releases

Packages

Contributors

Languages