Skip to content

Commit 068d326

Browse files
author
Steven
committed
add setText method
1 parent a4e4cfd commit 068d326

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/src/main/java/com/dx/dxloadingbutton/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void onClick(View view) {
3434
lb.startLoading();
3535
}
3636
});
37-
37+
3838
sucBtn.setOnClickListener(new View.OnClickListener() {
3939
@Override
4040
public void onClick(View view) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.graphics.Rect;
1818
import android.graphics.RectF;
1919
import android.graphics.Typeface;
20+
import android.text.TextUtils;
2021
import android.util.AttributeSet;
2122
import android.view.MotionEvent;
2223
import android.view.View;
@@ -299,6 +300,18 @@ public void setTypeface(Typeface typeface){
299300
}
300301
}
301302

303+
public void setText(String text){
304+
if(TextUtils.isEmpty(text)){
305+
return;
306+
}
307+
this.mText = text;
308+
mTextWidth = mTextPaint.measureText(mText);
309+
Rect bounds = new Rect();
310+
mTextPaint.getTextBounds(mText,0,mText.length(),bounds);
311+
mTextHeight = bounds.height();
312+
invalidate();
313+
}
314+
302315

303316
public void setResetAfterFailed(boolean resetAfterFailed){
304317
this.resetAfterFailed = resetAfterFailed;

0 commit comments

Comments
 (0)