【问题标题】:Android - how do I change the color of the spinner itself?Android - 如何更改微调器本身的颜色?
【发布时间】:2016-09-28 23:22:03
【问题描述】:
我的所有搜索都引导我找到有关如何更改微调器选项的文本颜色的指南,但是如何更改微调器本身的文本和箭头的颜色?
这是我的微调器的一个片段。它应该说“水星”。
这是我对这种风格的尝试。它确实将箭头更改为白色,但不是文本。我只将它应用于微调器,因为它会搞乱其余的活动。
<style name="Theme.LightText2" parent="AppTheme">
<item name="android:editTextColor">#ffffff</item>
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:textColorSecondary">#ffffff</item>
<item name="android:textColorTertiary">#ffffff</item>
<item name="android:textColorPrimaryInverse">#ffffff</item>
<item name="android:textColorSecondaryInverse">#ffffff</item>
<item name="android:textColorTertiaryInverse">#ffffff</item>
</style>
更新:我尝试通过清单将其应用于活动本身并且它有效,但它搞砸了我的其余活动。
【问题讨论】:
标签:
android
user-interface
styles
spinner
android-spinner
【解决方案1】:
创建数组适配器,它将从 Layout_resource 膨胀 TextView
然后将你的颜色设置为充气TextView
your_spinnersp.setAdapter(new ArrayAdapter<>(context,R.layout.txt_spinner,lst_data));
在布局中添加TextView
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="8dp" android:textSize="16sp"
android:background="#ff0000"
android :textColor="#ffff00"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
【解决方案2】:
像这样尝试并使用 spnrSelect.performClick();点击 rlSpinner 打开微调器
<RelativeLayout
android:id="@+id/rlSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/scale_20dp"
android:layout_marginRight="@dimen/scale_20dp"
android:layout_marginTop="@dimen/scale_1dp"
android:background="@null"
android:clickable="true">
<Spinner
android:id="@+id/spnrSelect"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="true"
android:dropDownWidth="@dimen/scale_300dp"
android:scrollbars="none"
android:spinnerMode="dropdown" />
<TextView
android:id="@+id/txtSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingBottom="@dimen/scale_1dp"
android:paddingRight="@dimen/scale_1dp"
android:paddingTop="@dimen/scale_1dp"
android:text="@string/txtSelect"
android:textColor="@color/edt_hint"
android:textColorHint="@color/edt_hint"
android:textSize="@dimen/txt_12" />
<ImageView
android:id="@+id/spnrDownArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/scale_10dp"
android:background="@drawable/arrow_icon"
android:rotation="90" />
</RelativeLayout>
【解决方案3】:
如果你想实现这一点,做一件事,采取一个文本视图并在右侧设置箭头图标(Drawableright)自定义你的文本文本视图,然后单击打开对话框,单选并在选定项目上将文本设置为文本视图