Home » Android » android – How do change the font size and font color from a Java file?

android – How do change the font size and font color from a Java file?

Posted by: admin June 15, 2020 Leave a comment

Questions:

How can I change the font color, size and button color from a Java file in Eclipse, not from an XML file?

How to&Answers:

For font size you can write it as

tv.setTextSize(20.0f);

For font color you can write it as

tv.setTextColor(Color.BLUE);

For button background color you can write it as

btn.setBackgroundColor(Color.CYAN);

Answer:

button.setTextColor(Color.WHITE);
button.setBackgroundColor(Color.BLUE);

Answer:

In the “Inherited XML Attributes” paragraph of the official documentation you can see either XML attributes (that you can change from XML) or related methods (which you can use in your Java code).

Answer:

Others already posted answers on how to do it in Java, but I guess these could help you as well.

How to do it in XML: