Skip to content

Commit e496e7e

Browse files
author
xiangdong.cheng
committed
add lb_cornerRadius attribute
1 parent cc183ee commit e496e7e

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

library/src/main/java/com/dx/dxloadingbutton/lib/LoadingButton.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ class LoadingButton @JvmOverloads constructor(
4444

4545
var animationEndAction: ((AnimationType) -> Unit)? = null
4646

47-
var textColor = DEFAULT_COLOR
47+
var textColor
48+
get() = mTextColor
4849
set(value) {
4950
mTextColor = value
5051
invalidate()
5152
}
5253

53-
var typeface: Typeface = Typeface.DEFAULT
54+
var typeface: Typeface
55+
get() = mTextPaint.typeface
5456
set(value) {
5557
mTextPaint.typeface = value
5658
invalidate()
5759
}
5860

59-
var text = ""
61+
var text
62+
get() = mText
6063
set(value) {
6164
if (text.isEmpty()) {
6265
return
@@ -70,14 +73,16 @@ class LoadingButton @JvmOverloads constructor(
7073
/**
7174
* set button text, dip
7275
*/
73-
var textSize = 16 * mDensity
76+
var textSize
77+
get() = (mTextPaint.textSize / mDensity).toInt()
7478
set(value) {
7579
mTextPaint.textSize = value * mDensity
7680
mTextWidth = mTextPaint.measureText(mText)
7781
invalidate()
7882
}
7983

80-
var cornerRadius = 2 * mDensity
84+
var cornerRadius
85+
get() = mButtonCorner
8186
set(value) {
8287
mButtonCorner = value
8388
invalidate()
@@ -165,6 +170,7 @@ class LoadingButton @JvmOverloads constructor(
165170
resetAfterFailed = ta.getBoolean(R.styleable.LoadingButton_lb_resetAfterFailed, true)
166171
mRippleColor = ta.getColor(R.styleable.LoadingButton_lb_btnRippleColor, Color.BLACK)
167172
mRippleAlpha = ta.getFloat(R.styleable.LoadingButton_lb_btnRippleAlpha, 0.3f)
173+
mButtonCorner = ta.getFloat(R.styleable.LoadingButton_lb_cornerRadius, 2 * mDensity)
168174
ta.recycle()
169175
}
170176

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<attr name="lb_resetAfterFailed" format="boolean" />
88
<attr name="lb_btnRippleColor" format="reference|color" />
99
<attr name="lb_btnRippleAlpha" format="float" />
10+
<attr name="lb_cornerRadius" format="float" />
1011
<attr name="lb_btnDisabledColor" format="reference|color" />
1112
<attr name="lb_disabledTextColor" format="reference|string" />
1213
</declare-styleable>

0 commit comments

Comments
 (0)