【问题标题】:changing spinner text color based on background color根据背景颜色更改微调器文本颜色
【发布时间】:2011-12-29 17:55:19
【问题描述】:

我有一个带有图像和文本视图的自定义微调器布局,但我注意到根据制造商的皮肤,您无法看到文本,因为颜色,即。白底白字,黑底黑字。

我还注意到我的其他非自定义微调器都没有这样做并且似乎会自动更改,所以我的问题是如何更改文本颜色以便可以阅读?

这是一个非自定义微调器

ArrayAdapter<CharSequence> cAdapter;
    cAdapter = ArrayAdapter.createFromResource(this, R.array.colors,android.R.layout.simple_spinner_item);
    int cSpinnerDD = android.R.layout.simple_spinner_dropdown_item;
    cAdapter.setDropDownViewResource(cSpinnerDD);
    color.setAdapter(cAdapter);

自定义微调器我只是覆盖视图以将图像与文本一起放入

这是它的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView android:id="@+id/icon_txt"
    android:paddingLeft="25dp"
    android:textSize="18sp"
    android:layout_marginTop="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>  
</LinearLayout>

【问题讨论】:

    标签: android spinner


    【解决方案1】:

    使用当前主题的默认文本颜色(存储在资源IDandroid.R.attr.textColorPrimary中):

    <TextView android:id="@+id/icon_txt"
        android:textColor="?android:attr/textColorPrimary"
        ... />
    

    【讨论】:

      【解决方案2】:

      我认为更改主题会改变列表视图的外观。

      我也被困在这一点上,但我所做的是我创建了一个新的 android 应用程序项目并选择了空白活动(代替空活动)并且它有效(我知道这不是一个好的解决方案,但它解决了我的问题)

      【讨论】:

      • 这不是答案
      猜你喜欢
      • 2016-06-02
      • 1970-01-01
      • 2015-12-31
      • 2022-10-18
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      相关资源
      最近更新 更多