如何prevent TextView的字体变化,当我们改变设备的字体样式三星设备 [英] How to prevent TextView font changing, when we change the Device font style in Samsung devices

查看:219
本文介绍了如何prevent TextView的字体变化,当我们改变设备的字体样式三星设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想说,我有一个奇怪的问题,在设置TextView的字体。 如果我更改设备字体样式从设置 - >显示,然后TextView的字体样式也得到改变。我怎么能prevent呢?

I would like say that I have a strange problem in setting textview font. If I change the Device font style from setting-> display, then textview font style also get changed. How can i prevent this?

下面是我的XML布局我的TextView。

Here is my textview in my xml layout.

<TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/title_bar_bg"
        android:fontFamily="sans-serif"
        android:typeface="sans"
        android:gravity="center"
        android:text="@string/people_finder"
        android:textColor="@color/WHITE"
        android:textSize="18sp"
        android:textStyle="bold">

    </TextView>

机器人:fontFamily中=无衬线 机器人:字体=SANS

android:fontFamily="sans-serif" android:typeface="sans"

此外,它工作正常在一些设备,如三星Galaxy盛大,三星注2。 但不工作的三星注8,三星注10.1等。

Also It is working fine in some device like Samsung Galaxy Grand, Samsung Note 2. But not working in Samsung Note 8, Samsung Note 10.1 etc.

还有没有其他的方法来做到这一点?

is there any other way to do this?

感谢

推荐答案

fontFamily中字体属性与Android原生的字体。如果你希望你的 TextViews 字体总是相同的,无论该设备字体设置,您需要通过编程设置自定义字样

fontFamily and typeface attributes are related to android native fonts. If you want your TextViews font to be always the same regardless the device font settings, you need to programmatically set a custom Typeface.

Typeface tf = Typeface.createFromAsset(context.getAssets(), "fontName.ttf"));
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setTypeface(tf);

这篇关于如何prevent TextView的字体变化,当我们改变设备的字体样式三星设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆