styles.xml中的Android Studio 3.0自定义字体

styles.xml中的Android Studio 3.0自定义字体,第1张

概述我无法在我的样式文件中设置自定义字体.<resources><stylename="AppTheme"parent="Theme.AppCompat.Light.NoActionBar">...<itemname="android:textViewStyle">@style/fontTextView</item>...

我无法在我的样式文件中设置自定义字体.

<resources>    <style name="Apptheme" parent="theme.AppCompat.light.NoActionbar">        ...        <item name="androID:textVIEwStyle">@style/FontTextVIEw</item>        ...    </style>    <style name="FontTextVIEw" parent="@androID:style/Widget.TextVIEw">        <item name="androID:FontFamily">@Font/example</item>    </style></resources>

我仍然在我的应用程序中看到默认字体.但是当我将FontFamily更改为其中一个默认值时,它会发生变化

    <style name="FontTextVIEw" parent="@androID:style/Widget.TextVIEw">        <item name="androID:FontFamily">monospace</item>    </style>

如果我以编程方式设置自定义字体,它也有效.

setTypeface(ResourcesCompat.getFont(context, R.Font.example));

如何使它适用于styles.xml中的自定义字体?

我将compiltSdkVersion设置为26,将buildToolsversion设置为26.0.2.我也在使用支持库:

  def supportVersion = '26.1.0'  implementation "com.androID.support:appcompat-v7:$supportVersion"

我的字体系列:

<?xml version="1.0" enCoding="utf-8"?><Font-family xmlns:androID="http://schemas.androID.com/apk/res/androID"         xmlns:app="http://schemas.androID.com/apk/res-auto"><Font    androID:FontStyle="normal"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="normal"    app:FontWeight="300"    app:Font="@Font/example_regular"/><Font    androID:FontStyle="normal"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="normal"    app:FontWeight="400"    app:Font="@Font/example_regular"/><Font    androID:FontStyle="normal"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="normal"    app:FontWeight="700"    app:Font="@Font/example_regular"/><Font    androID:FontStyle="italic"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="italic"    app:FontWeight="300"    app:Font="@Font/example_regular" /><Font    androID:FontStyle="italic"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="italic"    app:FontWeight="400"    app:Font="@Font/example_regular" /><Font    androID:FontStyle="italic"    androID:FontWeight="400"    androID:Font="@Font/example_regular"    app:FontStyle="italic"    app:FontWeight="700"    app:Font="@Font/example_regular" /></Font-family>

我使用相同的* ttf文件进行测试.

解决方法:

好.我解决了这个问题 – 这种行为的原因很简单……我正在扩展Activity而不是AppCompatActivity

总结

以上是内存溢出为你收集整理的styles.xml中的Android Studio 3.0自定义字体全部内容,希望文章能够帮你解决styles.xml中的Android Studio 3.0自定义字体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1119596.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存