Android:如何设置布局的文本大小?
我正在尝试在全局级别设置文本大小,但无法计算或找到方法来做到这一点。
例如,我有这样的内容:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/Table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
TableRows 和 TextViews 本身是根据用户输入动态生成的。
问题是我想根据资源文件全局设置基本 textSize ,而不必去触摸一堆代码。有没有办法告诉应用程序,“嘿应用程序,使用它作为所有文本视图的基本文本大小?”
或者换句话说,在 HTML 中,我可以在正文、div 和表格级别设置字体大小。我可以在布局(LinearLayout、TableLayout、ScrollView 等)级别执行类似的操作吗?
I am trying to set the textsize at a global level and cannot figure or find a way to do it.
For example I have something like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/Table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
The TableRows and TextViews themselves are generated dynamically depending on user input.
The problem is I would like to set the base textSize globally based on a resource file without having to go and touch a bunch of code. Is there a way to tell the app, "hey app, use this as your base textSize for all the textViews?"
Or phrased another way, in HTML I can set the font size at the body, div, and table levels. Is there something analogous I can do at one the layout (LinearLayout, TableLayout, ScrollView, etc.) levels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要为所有
TextView
设置全局样式,请在自定义主题中设置android:textViewStyle
属性,并将该主题应用到您的应用程序或单个 Activity。伪代码:
To set the global styling for all
TextView
s, set theandroid:textViewStyle
attribute in a custom theme and apply the theme to your application or individual activities.Pseudocode:
或者,如果您想设置默认的所有文本样式,但要覆盖某些内容的部分内容(例如本例中的按钮),您可以执行以下操作:
也许您最好的开始位置是: http://developer.android.com/design/style/index.html
Or if you wanted to set the default all around text style but override parts of it for certain things (like the button in this example) you could do something like this:
Probably your single best place to get started though would be: http://developer.android.com/design/style/index.html