gpt4 book ai didi

Android 在 Spinner 中更改文本颜色

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:52 24 4
gpt4 key购买 nike

我有一个微调器并使用一个 ArrayAdapter。在适配器中,我使用“android.R.layout.simple_list_item_1”,如下所示:

spinnerControlObjectType.setAdapter(new ArrayAdapter(getApplicationContext, android.R.layout.simple_list_item_1, list))

我查看了 android.R.layout.simple_list_item_1 并看到它具有如下文本样式:

android:textAppearance="?android:attr/textAppearanceListItemSmall"

我想在我的主题中覆盖“textAppearanceListItemSmall”以赋予它不同的颜色,我该怎么做?我不想子类化任何东西或编写代码样板。我确信有一种方法可以只更改 theme.xml 来更改颜色。

在 android 文档中写道:'...引用样式属性本质上是说,“在当前主题中使用此属性定义的样式。”...'(http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes)。他们说“已定义”和“在当前主题中”——我如何在当前主题中定义它?让我疯狂......

最佳答案

您应该只在您的主题中覆盖该属性,在此示例中,我使用 AppCompat 主题作为父主题,但您可以将其更改为任何其他主题。根据您的需要,您应该为不同版本的 Android 制作主题和样式资源:

<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:textAppearanceListItemSmall">@style/MySpinnerStyle</item>
</style>

<style name="MySpinnerStyle" parent="TextAppearance.AppCompat.Subhead">
<item name="android:textSize">13sp</item>
<item name="android:textColor">@color/white</item>
</style>

关于Android 在 Spinner 中更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36647158/

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