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

时间:2016-02-14 10:40:39

标签: java android css android-studio fonts

我想知道是否有办法将默认手机字体设置为我的应用。此时,我的应用程序从我的LG G2(purewhite字体)读取字体,并仅在对话框,零食栏和toast上设置它,而不是在textviews或spinners中。如何将字体传递给textview和spinners?

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

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

this answer,您可以创建自定义视图,例如:

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即可。主要好处是您不必单独为它们指定字体。

如果你想单独指定字体,那么:

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

如果您更喜欢使用图书馆,请查看Calligraphy,其中包含所有这些以及更多内容。

答案 1 :(得分:0)

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

我换了

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

    <style name="AppTheme" parent="android:Theme.DeviceDefault.NoActionBar">

在我的“styles.xml”

并添加了

    app:backgroundTint="@color/colorPrimary"
    app:rippleColor="@color/colorPrimary"

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

相关问题