如何确保android使用默认字体?

如何确保android使用默认字体?,android,android-fonts,Android,Android Fonts,我正在构建一个应用程序,希望确保它使用android提供的默认“sans”字体类型 我安装了一些奇怪的字体,并将其设置为手机使用的字体,以便测试我的操作是否正常 然后,我更改了所有屏幕使用的主题,使其包含以下行: <item name="android:typeface">sans</item> sans 但这没有任何效果 如果我将主题字体行更改为: <item name="android:typeface">serif</item> 衬线

我正在构建一个应用程序,希望确保它使用android提供的默认“sans”字体类型

我安装了一些奇怪的字体,并将其设置为手机使用的字体,以便测试我的操作是否正常

然后,我更改了所有屏幕使用的主题,使其包含以下行:

<item name="android:typeface">sans</item>
sans
但这没有任何效果

如果我将主题字体行更改为:

<item name="android:typeface">serif</item>
衬线 然后它会工作,奇怪的字体不会显示,但我得到默认的android serif字体。。。 当我使用单空间时也会发生同样的情况

但是当我使用sans(或normal)时,它使用新安装的字体

有人知道实现这一点的好方法吗


编辑:我需要一种方法来设置整个应用程序,而不是每个项目单独


Edit2:即使我在xml中设置它,它也不起作用。 到目前为止,我认为衬线已经生效,因为这种奇怪的字体没有衬线版本。 所以android默认使用自己的字体

如何让andoid始终使用自己的内置字体?

您可以这样做

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="serif"
    android:text="@string/hello" />

变成这样:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

通过定义xml主题文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">shreif</item>
    </style>
</resources>

填补家长的空缺
包装内容
#00FF00
史莱夫
您还可以将样式应用于应用程序的所有活动:

<application android:theme="@style/CustomTheme">

或者只是一项活动:

<activity android:theme="@android:style/Theme.Dialog">

您可以这样做

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="serif"
    android:text="@string/hello" />

变成这样:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

通过定义xml主题文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">shreif</item>
    </style>
</resources>

填补家长的空缺
包装内容
#00FF00
史莱夫
您还可以将样式应用于应用程序的所有活动:

<application android:theme="@style/CustomTheme">

或者只是一项活动:

<activity android:theme="@android:style/Theme.Dialog">

这是我不久前遇到的一个问题,我从未找到答案。 没关系。最后我想:每个设备供应商都可以给你另一种默认字体

所以我决定在应用程序中打包“我自己的”字体


(啊,好吧,我想这里的每个人都在学习)

这是我不久前提出的一个问题,但从未找到答案。 没关系。最后我想:每个设备供应商都可以给你另一种默认字体

所以我决定在应用程序中打包“我自己的”字体


(啊,好吧,我想这里的每个人都在学习)

不,我有超过10个活动,很多观点,两个SurfaceView,上面还有文字。这是行不通的。我需要一种方法来为整个应用程序设置它。我这样做了,不起作用,它尝试使用新安装字体的sans/serif/monospace版本,而不是默认的droid字体。不,我有10多个活动,很多视图,两个SurfaceView,其中还有文字。这是行不通的。我需要一种方法来为整个应用程序设置它。我这样做了,但不起作用,它尝试使用新安装字体的sans/serif/monospace版本,而不是默认的droid字体。