gpt4 book ai didi

android - 使用样式而不是 android :textAppearance

转载 作者:行者123 更新时间:2023-12-05 00:00:09 26 4
gpt4 key购买 nike

android:textAppearance 允许您为 TextView 的某些属性应用额外的样式层。我想知道此功能的灵 active 是否超过了它的复杂性。

  • 出于任何技术或视觉原因,是否需要 android:textAppearance
  • 在整个项目中完全依赖 style 并在布局中省略 android:textAppearance 的使用可能会产生什么后果?
  • 如果它也从样式中省略怎么办?

这里有两个推荐使用 android:textAppearance 的指南:

Styling Views on Android (Without Going Crazy)

TextAppearance allows you to merge two styles for some of the most commonly modified text attributes. Take a look at all your styles: how many of them only modify how the text looks? In those cases, you could instead just modify the TextAppearance.

Best practices for happy Android resources

To ensure consistent-looking TextViews, do not define any of the TextAppearance attributes in a normal style, but always set a TextAppearance from your library on that style’s android:textAppearance field.

最佳答案

查看 TextView.java,似乎没有任何由 android:textAppearance 定义的属性不能在 上设置>TextView 直接。因此,似乎没有任何技术原因需要使用它们来直接定义样式中的属性,至少在配置 TextView 外观的能力方面是这样。

这意味着您可以避免在您的布局和样式中使用它而不会产生任何不利影响,前提是您覆盖所有关联的属性。基本主题为各种小部件定义了许多不同的标准 android:textAppearance,因此您应该检查所有小部件是否已正确覆盖。

根据我的经验,如果您希望您的应用看起来集成到设备的其余部分,android:textAppearance 是最有用的。所以如果你需要大文本,你可以使用 android:textAppearance="?android:attr/textAppearanceLarge" 现在你的文本很大了!无需知道对于给定的设备/屏幕尺寸/等意味着多少 sp

但是,如果您的应用具有高度样式化,并且您无论如何都会覆盖所有文本大小,那么 android:textAppearance 的附加值就会​​减少。您当然可以按照上面帖子中的引用使用它,但如果它不适合您的样式系统,请随意忽略它。它只是帮助您在所有设备上获得美观应用的另一种工具。

如果您选择不使用您的应用程序,我还建议您格外确保在各种设备上试用它,只是为了确保您没有忘记覆盖默认的 android:textAppearance.

关于android - 使用样式而不是 android :textAppearance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50613786/

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