android - 在 XML 中更改 Spinner 下拉箭头的颜色

标签 android android-layout colors android-spinner android-color

正如我在问题中所写,我想更改 XML 中 Spinner 的下拉箭头(默认箭头,而不是自定义箭头或类似的东西)的颜色,但问题是我无法从 XML 中找到任何可以引用它的内容。

有可能吗?如果是,如何更改颜色?

提前致谢。

最佳答案

有三种方法可以实现。

1.通过代码:

在您的 xml 中,确保您的微调器有一个 id。假设我们有一个 id 为“spinner”的微调器。

在您的代码中,在 onCreate() 中添加以下内容:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);

其中红色是您在 values 文件夹的 colors.xml 中定义的颜色。

<强>2。通过xml:

对于 API 21+:

<Spinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/red" />

或者如果你使用支持库,你可以使用:

<android.support.v7.widget.AppCompatSpinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@color/red" />

3.通过drawables:

您可以使用此在线工具:http://android-holo-colors.com

这将为您希望使用首选颜色的任何 View 生成自定义可绘制对象。确保选择微调器,然后下载资源。

关于android - 在 XML 中更改 Spinner 下拉箭头的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32166347/

相关文章:

android - 比较按钮的背景资源

android - 更新 Gradle 后自动生成的文件错误

android - 如何将 textview 放置在 android 的布局边框上?

swift - Xcode/Swift 中的颜色和主题

android - getDrawingCache while NoTitleBar style set for the application in Android

android - 使用 TimePicker 或 NumberPicker 查看对话框首选项时旋转 Android 设备会导致应用程序崩溃

android - 如何在 ImageViewTouch 中使图像适合全屏

xml - FrameLayout、LinearLayout 和 ScrollView,android Studio

python - 使用 Python 和 CV2 检测红色和蓝色方 block ( bean 袋)

python - 使用 matplotlib 将 RGBA 元组转换为十六进制