更改整个应用程序所有文本视图的字体,包括按钮和编辑文本
Change the font of entire app all textview, including buttons and edittexts
我想将应用程序字体更改为roboto
。我也试过this link。
但它只改变了 textview 字体,没有改变 listview 适配器 XML 字体。
如何将整个应用程序字体更改为 roboto
?
将此放入您的 style.xml
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
你也必须改变这个。
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
开发者网站已经提供了这方面的信息。
让我知道进度
您可以将内容视图/或任何视图组传递给此函数和字体。
public void replaceFonts(ViewGroup viewTree, TypeFace typeface) {
Stack<ViewGroup> stackOfViewGroup = new Stack<ViewGroup>();
stackOfViewGroup.push(viewTree);
while (!stackOfViewGroup.isEmpty()) {
ViewGroup tree = stackOfViewGroup.pop();
for (int i = 0; i < tree.getChildCount(); i++) {
View child = tree.getChildAt(i);
if (child instanceof ViewGroup) {
// recursive call
stackOfViewGroup.push((ViewGroup) child);
}else if (child instanceof Button) {
((Button) child).setTypeface(typeface);
}else if (child instanceof EditText) {
((EditText) child).setTypeface(typeface);
} else if (child instanceof TextView) {
// base case
((TextView) child).setTypeface(typeface);
}
}
}
}
或者创建自定义按钮、EditText、TextView 并将其添加到视图组。在 Google.
上搜索 FontTextView
我想将应用程序字体更改为roboto
。我也试过this link。
但它只改变了 textview 字体,没有改变 listview 适配器 XML 字体。
如何将整个应用程序字体更改为 roboto
?
将此放入您的 style.xml
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
你也必须改变这个。
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
开发者网站已经提供了这方面的信息。 让我知道进度
您可以将内容视图/或任何视图组传递给此函数和字体。
public void replaceFonts(ViewGroup viewTree, TypeFace typeface) {
Stack<ViewGroup> stackOfViewGroup = new Stack<ViewGroup>();
stackOfViewGroup.push(viewTree);
while (!stackOfViewGroup.isEmpty()) {
ViewGroup tree = stackOfViewGroup.pop();
for (int i = 0; i < tree.getChildCount(); i++) {
View child = tree.getChildAt(i);
if (child instanceof ViewGroup) {
// recursive call
stackOfViewGroup.push((ViewGroup) child);
}else if (child instanceof Button) {
((Button) child).setTypeface(typeface);
}else if (child instanceof EditText) {
((EditText) child).setTypeface(typeface);
} else if (child instanceof TextView) {
// base case
((TextView) child).setTypeface(typeface);
}
}
}
}
或者创建自定义按钮、EditText、TextView 并将其添加到视图组。在 Google.
上搜索 FontTextView