【问题标题】:Changing the Color of a Spinner更改微调器的颜色
【发布时间】:2019-10-14 19:40:45
【问题描述】:

我有一个微调器,当它没有被点击时我想改变它的颜色。活动中的视图。单击时,我设法更改了文本和背景的颜色,但没有更改默认文本和背景。而且由于应用程序的背景很暗,因此很难看清。我怎样才能做到这一点。这是我在 activity_main.xml 上的微调器代码

<Spinner
        android:id="@+id/spinner"
        android:layout_width="114dp"
        android:layout_height="33dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:theme="@style/Spinner"
        app:layout_constraintBottom_toTopOf="@+id/ping_btn"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.507"
        app:layout_constraintStart_toEndOf="@+id/editText"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.025" />

我的微调器风格

<style name="Spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
        <item name="android:paddingStart">0dp</item>
        <item name="android:paddingEnd">0dp</item>
        <item name="android:textColor">@color/textColor</item>
        <item name="android:backgroundTint">@color/background</item>
        <item name="android:textSize">14sp</item>
    </style>

这是应用程序的屏幕截图 http://pctechtips.org/apps/droid.png

【问题讨论】:

  • 你试过选择器吗?
  • @Md.Asaduzzaman 什么选择器?

标签: android styles spinner


【解决方案1】:

为您的微调器项目制作一个自定义 XML 文件。

spinner_item.xml:

为此文件中的文本提供您自定义的颜色和大小。

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

<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:gravity="left"  
    android:textColor="#FF0000"         
    android:padding="5dip"
    />

现在使用此文件显示您的微调器项目,例如:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item,list);

您不需要设置下拉资源。 spinner_item.xml 仅用于在 spinner 中显示您的项目。

来自“How to change spinner text size and text color?”的引用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    相关资源
    最近更新 更多