ShapeButton introduction

Click on ShapeButton to access the original project, welcome star fork, and issue if you have a problem

1. Screenshot of the real machine

2. Version and language

3. Add a reference

3.1 Add build. Gradle in the project root directory

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

3.2 Adding a Dependency

  dependencies {
    implementation 'com. Making. SakurajimaMaii: ShapeButton: 0.0.5}Copy the code

4. Supported button types

  • Round/oval button
  • Rectangular button
  • Rounded rectangle button
  • Arbitrary rounded rectangle button

5. Currently supported four click states

  • The default (normal)
  • Pressed or touched
  • Get focus
  • Unavailable (unable)

6. Property Settings

6.1 Layout File Declaration

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

6.2 Setting Properties

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()
}
Copy the code

Note that the create() method must be called at the end, otherwise it will not take effect.

Related Attributes

The property name Attribute types Attributes that Attribute values
button_shape dimension Button shape oval_shape

rect_shape

rounded_rect_shape

any_rounded_rect_shape
button_rect_width dimension Rectangular button width
button_rect_height dimension Height of the rectangle button
button_oval_radius dimension Radius of the circular button
button_rounded_rect_corner_radius dimension The rounded radius of the rectangle button
button_left_top_corner_radius dimension The four rounded radii of any rounded rectangle button
button_left_bottom_corner_radius dimension The four rounded radii of any rounded rectangle button
button_right_top_corner_radius dimension The four rounded radii of any rounded rectangle button
button_right_bottom_corner_radius dimension The four rounded radii of any rounded rectangle button
button_is_solid boolean Whether the button is filled true

false
button_is_solid_color_gradient boolean Whether the button uses a gradient fill color true

false
button_start_solid_color color Gradient start color
button_center_solid_color color Gradient intermediate
button_end_solid_color color Gradient end color
button_gradient_type dimension The gradient direction linear_gradient

radial_gradient

sweep_shape
button_stroke_width dimension Button border width
button_normal_bg_color color Default background color
button_pressed_bg_color color Refers to the background color of the control when the user clicks or touches it
button_focused_bg_color color Refers to the background color when the current control gains focus
button_unable_bg_color color Refers to the background color when the current window is in focus
button_normal_stroke_color color Default state border color
button_pressed_stroke_color color Refers to the border color of the control when the user clicks or touches it
button_focused_stroke_color color Refers to the border color when the current control gets focus
button_unable_stroke_color color Refers to the border color of the current window when it is in focus