MaterialDesignLibrary icon indicating copy to clipboard operation
MaterialDesignLibrary copied to clipboard

How I can change the textsize in button??

Open Zane96 opened this issue 9 years ago • 4 comments

How I can change the text size in button??

Zane96 avatar Sep 23 '15 09:09 Zane96

ButtonRectangle extends Button, but you cannot access TextView using buttonRectangle.getTextView(), this will only get you a null object. The author creates a private field (TextView)textButton instead of using Button.getTextView(), so you can only get this field using Java Reflection. Here is my solution:

ButtonRectangle buttonRectangle = (ButtonRectangle) this.findViewById("YOUR BUTTON RESOURCE ID");
try {
   Field textButton = buttonRectangle.getClass().getDeclaredField("textButton");
   textButton.setAccessible(true);
   //Here you can get the textview, then you can do whatever you want
   TextView textView = (TextView) textButton.get(registerButton);
} catch (NoSuchFieldException e) {
   e.printStackTrace();
} catch (IllegalAccessException e) {
   e.printStackTrace();
}

sousuo28 avatar Sep 30 '15 03:09 sousuo28

你是中国人吗?。。英文不错!谢了

Zane96 avatar Sep 30 '15 14:09 Zane96

But I use the Flat Button, does it as same as the ButtonRectangle?

Zane96 avatar Oct 01 '15 05:10 Zane96

@sousuo28 Thank you!, that helped me to change the text color from the rectangle button.

LDMR-0 avatar Oct 12 '15 14:10 LDMR-0