android - 使用 Holo-Light 主题不会为 TextView 设置正确的颜色

标签 android android-listview actionbarsherlock android-theme android-support-library

背景

我正在为我的应用“App Manager”添加“Holo”和“Holo Light”主题选择器(也许还有深色操作栏)。现在,我首先通过 XML 文件试用它们。

问题

我正在使用 Google 的支持库并尝试主题,但无论我使用什么属性和主题,我的 listView 上的 textViews 的颜色都是错误的。

listView 包含 2 个这样定义的 TextView:

<TextView
    android:id="@+id/appLabelTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/isSystemAppImageView"
    android:layout_toRightOf="@+id/appIconImageView"
    android:ellipsize="marquee"
    android:text="label"
    android:textAppearance="?android:attr/textAppearanceLarge"
    tools:ignore="HardcodedText" />

<TextView
    android:id="@+id/appDescriptionTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/appLabelTextView"
    android:layout_below="@+id/appLabelTextView"
    android:layout_toLeftOf="@+id/isSystemAppImageView"
    android:ellipsize="marquee"
    android:text="description"
    android:textAppearance="?android:attr/textAppearanceSmall"
    tools:ignore="HardcodedText" />

Theme.AppCompat.LightTheme.AppCompat:

enter image description here enter image description here

当我以编程方式完成这一切时,以及当我使用 ActionBarSherlock 库时,也会发生同样的情况。

这是我使用的主题配置(这次尝试了 ActionBarSherlock,但对于普通支持库也是如此):

<style name="BaseTheme" parent="@style/Theme.Sherlock.Light"></style>

<style name="AppTheme" parent="@style/BaseTheme">
    <item name="android:listSeparatorTextViewStyle">@style/PreferenceListHeader</item>
    <item name="android:windowBackground">@color/normal_window_background</item>
</style>

和 list :

<application
    android:name="com.lb.app_manager.utils.App"
    android:allowBackup="true"
    android:description="@string/app_description"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

我在这里展示的 Activity 没有任何代码或 XML 将主题设置为与上面写的不同。

我尝试过的

我已尝试查看样本,但发现 XML 和代码之间没有明显差异。他们工作得很好......

此外,出于某种原因,偏好 Activity 显示得很好。

ActionBarShelock 库中存在同样的问题。

问题

怎么可能?应该怎么做才能解决它?

最佳答案

我找到了这个问题的原因。

它与任何 XML 或设置样式无关。

是因为适配器的LayourInflater。我是通过应用程序上下文而不是 Activity 之一创建它的。

这也解释了为什么我对示例项目的测试工作正常,因为我检查了错误的东西...

关于android - 使用 Holo-Light 主题不会为 TextView 设置正确的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22924923/

相关文章:

android - 在其他小部件上 flutter 阴影

java - Android将单个.java文件编译为.class

android - 如何将 ListView 项目标记为 `read` 一旦显示几秒钟?

android - 具有两个按钮的 ListView 行中的 OnClick 事件

android - 在运行 API <11 的设备上使用 ActionBarSherlock 的全屏模式

android - 以编程方式添加多个 fragment

android - android-support-v7-mediarouter 中的 styles.xml 错误

java - Android Studio itemsAdapter 和自定义 ListView 不起作用

android - 如何保留 fragment ListView 内容?

android - 使用最新的支持版本在 MenuInflater Android 中获取空值