gpt4 book ai didi

android - 无法覆盖 AppTheme 字体

转载 作者:行者123 更新时间:2023-11-29 02:30:00 25 4
gpt4 key购买 nike

这是我在 style.xml 中的 AppTheme 样式

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily" tools:targetApi="jelly_bean">@font/montserrat_regular</item>
<item name="fontFamily">@font/montserrat_regular</item>
</style>

manifest.xml中的application标签

 <application
android:name=".Amelio"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"

我想要的是在 AppTheme 中设置 fontFamily,这样我就不必在应用程序的每个组件上都设置它。但我想在应用程序中的某些 TextView 上设置自定义字体。

问题是当我在 AppTheme 中设置 fontFamily 时,我无法在任何 TextView 上设置字体或 fontFamily .但是当我从 AppTheme 中删除 fontFamilyfont 时,我可以设置它。这是预览 -

  1. AppTheme风格的字体属性

with font in AppTheme

  1. 在 AppTheme 样式中没有字体属性

with font in AppTheme

注意:我知道可以使用 font 或 fontFamily,如果可行的话,我只是尝试了两者。所以请忽略它。

最佳答案

Khemraj 的建议是正确的 https://stackoverflow.com/a/16407123/6891563 ,因为当你想覆盖某些组件的属性时,你需要覆盖它的样式,所以当你添加(取自 Hussein El Feky)时:

<!-- Into a styles.xml--!>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>

<!-- Into a themes.xml--!>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="buttonStyle">@style/RobotoButtonStyle</item>
</style>

您正在覆盖所有 TextView 的样式,因此无论何时您使用 AppTheme,TextView 组件都会监​​听 RobotoTextViewStyle 属性并使用它们。

关于android - 无法覆盖 AppTheme 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50056649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com