是否可以在Android应用程序中设置自定义字体?
我尝试了这里发布的内容,但不知道我的extends Application
课程在哪里...
有什么帮助吗?
编辑:
我尝试了以下方法:
添加一个从 Application
从我的学校叫这个新班AndroidManifest.xml
。
我按照自己的风格进行了添加。
MyApp.java:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "raleway_regular.ttf");
// This FontsOverride comes from the example I posted above
}
}
AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MyApp"
android:theme="@style/AppTheme">
....
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fontFamily">default</item>
</style>
但是我的字体仍然没有变化...知道吗?
然后MyApp
调用该类。但是对我的字体没有影响...
EDIT2:在为按钮设置自定义样式后,我意识到我的按钮将应用自定义字体。这是我的自定义按钮样式:
<style name="MyButtonStyle" parent="Widget.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
这是现在的样子:
所以:我的按钮正在应用样式,但不是TextView
。关于为什么我的自定义字体未应用于应用程序中的所有项目的任何想法?
试试这个代码。但是您需要使用初始化代码中的TextView或Button findViewByIdMethod(int id)
。
TextView yourTextView = findViewById(R.id.YourTextViewId);
Typeface font = Typeface.createFromAsset(getActivity().getAssets(),"raleway_regular.ttf");
yourTextView.setTypeface(font);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句