gpt4 book ai didi

android - 如何从布局中引用颜色

转载 作者:行者123 更新时间:2023-11-30 01:13:38 25 4
gpt4 key购买 nike

这是我的 styles.xml 文件

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#6d3655</item>
<item name="colorPrimaryDark">#442142</item>
<item name="colorAccent">#de8573</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

我想从我的布局中访问 c​​olorPrimary。例如,我尝试将颜色应用于某些 TextField。我将“textColor”属性设置为“@style/AppTheme.colorPrimary”,但它不起作用。为什么?

最佳答案

您不必将颜色保存为 colors.xml 中的资源。您可以像这样直接从主题中引用颜色(或任何其他值):

android:textColor="?attr/colorPrimary"

?attr/ 是访问主题属性值的语法。

关于android - 如何从布局中引用颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38172271/

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