eclipse 如何从 Java 文件更改字体大小和字体颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7157069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do change the font size and font color from a Java file?
提问by sheraz amin
How can I change the font color, size and button color from a Java file in Eclipse, not from an XML file?
如何从 Eclipse 中的 Java 文件而不是 XML 文件更改字体颜色、大小和按钮颜色?
回答by Lavanya
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);
回答by Onuray Sahin
button.setTextColor(Color.WHITE);
button.setBackgroundColor(Color.BLUE);
回答by Andrei Buneyeu
In the "Inherited XML Attributes
" paragraph of the official documentationyou can see either XML attributes (that you can change from XML) or related methods (which you can use in your Java code).
在官方文档的“ Inherited XML Attributes
”段落中,您可以看到 XML 属性(可以从 XML 更改)或相关方法(可以在 Java 代码中使用)。
回答by corecase
Others already posted answers on how to do it in Java, but I guess these could help you as well.
其他人已经发布了有关如何在 Java 中执行此操作的答案,但我想这些也可以帮助您。
How to do it in XML:
如何在 XML 中执行此操作:
Button Styling--Link changed.