Him*_*shu 6 fonts android textview typeface
我想说我在设置textview字体时有一个奇怪的问题.如果我从设置 - >显示更改设备字体样式,则textview字体样式也会更改.我该如何防止这种情况?
这是我的xml布局中的textview.
<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>
Run Code Online (Sandbox Code Playgroud)
android:fontFamily ="sans-serif"android:typeface ="sans"
它也适用于三星Galaxy Grand,三星Note 2等设备.但不适用于三星Note 8,三星Note 10.1等.
还有其他办法吗?
谢谢
fontFamily和typeface属性与android原生字体有关.如果您希望TextViews无论设备字体设置如何,您的字体始终相同,您需要以编程方式设置自定义Typeface.
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fontName.ttf"));
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setTypeface(tf);
Run Code Online (Sandbox Code Playgroud)
作为旁注,Calligraphy项目实际上可以直接从布局xml设置自定义字体.
| 归档时间: |
|
| 查看次数: |
4308 次 |
| 最近记录: |