Java 如何为我的整个应用设置默认手机字体

Java 如何为我的整个应用设置默认手机字体,java,android,css,android-studio,fonts,Java,Android,Css,Android Studio,Fonts,我想知道是否有办法为我的应用程序设置默认手机字体。此时,我的应用程序从我的LG G2(纯白色字体)读取字体,并仅在对话框、snackbar和烤面包上设置字体,而不是在文本视图或微调器中设置。如何将字体传递给textview和微调器 有几种方法可以做到这一点 从中,可以创建自定义视图,例如: public class YourTextView extends TextView { public YourTextView(Context context, AttributeSet attrs,

我想知道是否有办法为我的应用程序设置默认手机字体。此时,我的应用程序从我的LG G2(纯白色字体)读取字体,并仅在对话框、snackbar和烤面包上设置字体,而不是在文本视图或微调器中设置。如何将字体传递给textview和微调器


有几种方法可以做到这一点

从中,可以创建自定义视图,例如:

public class YourTextView extends TextView {

public YourTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

public YourTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public YourTextView(Context context) {
    super(context);
    init();
}

private void init() {
    Typeface tf = Typeface.createFromAsset(context.getAssets(),
        "fonts/helveticaneue.ttf");
    setTypeface(tf);
}
}
然后,您可以简单地在布局中使用此文本视图。主要的好处是,您不必为它们单独指定字体

如果要单独指定字体,请执行以下操作:

 TextView tv=(TextView)findViewById(R.id.custom);
 Typeface face=Typeface.createFromAsset(getAssets(),"fonts/Verdana.ttf");
 tv.setTypeface(face);

如果您更愿意使用库,请查看,它可以完成所有这些以及更多功能。

好的,我找到了解决方案:

我换了

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

在我的浮动按钮代码(android.support.design.widget.FloatingActionButton)

中,我必须声明我自己的字体,我希望应用程序读取手机的字体。@giannisj5“手机的字体”是什么意思?“手机”,即未受污染的android操作系统只有一个默认字体系列,即sans、serif、roboto等。默认情况下,所有应用程序都可以使用这些字体。例如,如果用户使用启动器设置了自定义字体,那么恐怕没有获取该字体的一般规则。或者它是特定于供应商的。看看我的图片,我的朋友,对话框确实想要我想要的:将默认手机字体(purewhite.ttf,LG G2的默认字体)设置为字母,为什么文本视图不这样做?
    <style name="AppTheme" parent="android:Theme.DeviceDefault.NoActionBar">
    app:backgroundTint="@color/colorPrimary"
    app:rippleColor="@color/colorPrimary"