Android自定义字体-适用于系统组件,例如Actionbar,Toast,Dialogs [英] Android custom fonts - for system components like Actionbar, Toast, Dialogs
问题描述
我正在将应用程序翻译为不支持的语言-设备上缺少字体. 因此,我向应用程序添加了字体,并更改了所有TextViews,EditTexts,Button的字体. 另外,我还能够更改WebView中的字体. 但是现在我需要为所有系统组件更改字体:
I am working on application translated to languages that are not supported - missing fonts on devices. So I added fonts to application and changed typeface for all TextViews, EditTexts, Buttons. Also I was able to change fonts in WebView. But now I need to change typeface for all system components:
-
ActionBar:
ActionBar:
- 标题下拉列表
- 菜单
- ShareActionProvider
- ActionItems
- ActionItems溢出
对话框
是否有一种方法可以更改此组件的字体. 可能所有人中都有一些TextView -只是知道他们的ID以找到他们.
Is there a way to change typeface for this components. Probably all have some TextView in them - just to know their id to find them.
请不要在TextView上发布有关更改字体的答案!
Please do not post answers about changing Typeface on TextView!
推荐答案
- 用于操作栏:
使用actionbar sherlock( http://actionbarsherlock.com/)并自定义其代码:
use actionbar sherlock (http://actionbarsherlock.com/) and customize its code:
在com.actionbarsherlock.app.Actionbar中添加以下两个抽象方法:
in com.actionbarsherlock.app.Actionbar add these two abstract methods:
public abstract void setTitleTypeface(Typeface TF);
public abstract void setSubtitleTypeface(Typeface TF);
并在com.actionbarsherlock.internal.app.ActionBarImpl中覆盖这些方法
and override these methods in com.actionbarsherlock.internal.app.ActionBarImpl
@Override
public void setTitleTypeface(Typeface TF) {
mActionView.setTitleTypeface(TF); }
@Override
public void setSubtitleTypeface(Typeface TF) {
mActionView.setSubtitleTypeface(TF); }
,并且在com.actionbarsherlock.internal.app.ActionBarWrapper中也是如此
and also in com.actionbarsherlock.internal.app.ActionBarWrapper like this
@Override
public void setTitleTypeface(Typeface TF) {}
@Override
public void setSubtitleTypeface(Typeface TF) {}
最后在com.actionbarsherlock.internal.widget.ActionBarView中添加以下方法:
and finally in com.actionbarsherlock.internal.widget.ActionBarView add these methods:
public void setTitleTypeface(Typeface TF){
mTitleView.setTypeface(TF);
}
public void setSubtitleTypeface(Typeface TF){
mSubtitleView.setTypeface(TF);
}
,现在像这样在您的SherlockActivity中使用它:
and now use it in your SherlockActivity like this:
Typeface TF = Typeface.createFromAsset(getApplication().getAssets(),
"Arial.ttf");
getSupportActionBar().setTitleTypeface(TF);
请确保没有更好的方法!
2.对于对话框,系统设置......您应该这样更改代码!
这篇关于Android自定义字体-适用于系统组件,例如Actionbar,Toast,Dialogs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!