如何prevent TextView的字体变化,当我们改变设备的字体样式三星设备字体、设备、当我们、样式

由网友(叼花硬汉)分享简介:我想说,我有一个奇怪的问题,在设置TextView的字体。如果我更改设备字体样式从设置 - >显示,然后TextView的字体样式也得到改变。我怎么能prevent呢?I would like say that I have a strange problem in setting textview font.I...

我想说,我有一个奇怪的问题,在设置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);
阅读全文

相关推荐

最新文章