gpt4 book ai didi

android - 在一个位置为布局中的所有 TextView 元素设置样式

转载 作者:太空狗 更新时间:2023-10-29 12:52:43 25 4
gpt4 key购买 nike

有没有一种方法可以将样式应用于布局 xml 中特定类型的所有元素,而无需实际向所有元素添加样式属性?

我在 GridLayout 中有很多 TextView 元素。如果我可以说所有 TextView 元素都应该具有“CellFont”样式,而不必将该语句实际放入每个 TextView 元素中,那就太好了。

解决方案如下:

将 GridLayoutCellFont 样式添加到 style.xml 并将该样式作为 android:theme 添加到应用程序 list 中的 Activity。

样式.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="GridLayoutCellFont">
<item name="android:textSize">22dp</item>
</style>

</resources>

list :

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:theme="@style/GridLayoutCellFont"
android:label="@string/app_name"
android:name=".TestLayoutsActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

最佳答案

您可以使用样式或设置新主题的两个选项阅读更多信息 Styles and Themes教程

关于android - 在一个位置为布局中的所有 TextView 元素设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10346611/

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