当我们在三星设备中更改设备字体样式时,如何防止 TextView 字体更改 [英] How to prevent TextView font changing, when we change the Device font style in Samsung devices
问题描述
我想说我在设置 textview 字体时遇到了一个奇怪的问题.如果我从设置更改设备字体样式->显示,然后 textview 字体样式也会改变.我怎样才能防止这种情况发生?
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 布局中的文本视图.
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"/>
android:fontFamily=无衬线"android:typeface="sans"
此外,它在三星 Galaxy Grand、三星 Note 2 等设备上也能正常工作.但不适用于三星 Note 8、三星 Note 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.
还有其他方法吗?
谢谢
推荐答案
fontFamily
和 typeface
属性与android原生字体相关.如果您希望您的 TextViews
字体始终相同而不管设备字体设置,您需要以编程方式设置自定义 Typeface
.
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);
<小时>
附带说明,Calligraphy 项目可以直接从布局 xml 中实际设置自定义字体.
As a side note, Calligraphy project enables actually setting custom font directly from a layout xml.
这篇关于当我们在三星设备中更改设备字体样式时,如何防止 TextView 字体更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!