更改android中微调器上小三角形的颜色 [英] Change colour of small triangle on spinner in android

查看:20
本文介绍了更改android中微调器上小三角形的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改微调器右下角小三角形的颜色,如图所示?它现在显示默认的灰色.像这样

How can I change the colour of small triangle at the bottom right corner of spinner like shown in the image? It is showing default grey colour right now. like this

推荐答案

要获得正确的图像,您可以转到 Android Asset Studio 站点并选择 Android Holo Colors Generator.这将创建您可能需要的所有资产,包括三角形".它还生成实现更改的 XML 文件.

To get the correct images, you can go to Android Asset Studio site and choose the Android Holo Colors Generator. This will create all the assets you might need, including the "triangle". It also generates the XML files that implement the changes.

以下是示例 XML 文件:

Here are the example XML files:

自定义颜色:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="apptheme_color">#33b5e5</color>
</resources>

自定义微调样式:

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

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="SpinnerAppTheme" parent="android:Widget.Spinner">
      <item name="android:background">@drawable/apptheme_spinner_background_holo_light</item>
      <item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
  </style>

  <style name="SpinnerDropDownItemAppTheme" parent="android:Widget.DropDownItem.Spinner">
      <item name="android:checkMark">@drawable/apptheme_btn_radio_holo_light</item>
  </style>
</resources>

自定义应用主题:

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

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="AppTheme" parent="@style/_AppTheme"/>

  <style name="_AppTheme" parent="Theme.AppCompat.Light">

    <item name="android:spinnerStyle">@style/SpinnerAppTheme</item>

    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItemAppTheme</item>

  </style>

</resources>

<小时>

如您所见,这些样式也引用了许多可绘制对象.


As you can see, there are also many drawables that are referenced by these styles.

以下是您要更改的三角形"的特定内容:

Here is the one specific to the "triangle" you want to change:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false"
          android:drawable="@drawable/apptheme_spinner_disabled_holo_light" />
    <item android:state_pressed="true"
          android:drawable="@drawable/apptheme_spinner_pressed_holo_light" />
    <item android:state_pressed="false" android:state_focused="true"
          android:drawable="@drawable/apptheme_spinner_focused_holo_light" />
    <item android:drawable="@drawable/apptheme_spinner_default_holo_light" />
</selector>

我不认为这是完整列出每个文件的正确位置,因为您可以直接从引用的工具中获取所有文件.

I don't think this is the right place to list every file completely, since you can get them all directly from the referenced tool.

注意:这是为整个应用设置主题的方式,以便所有微调器都更新为自定义样式.

Note: this is the way to theme your whole app so that all spinners are updated to the custom style.

如果您正在寻找一种快速而肮脏的方法来更改一个微调器,请查看 Ricky 在他的评论中引用的那篇文章:

If you are looking for a quick and dirty way to change just one spinner, then check out that article referenced by Ricky in his comment:

无论如何我都推荐阅读它,因为它很好地解释了这个过程,并且会帮助你理解我的其余答案.

I recommend reading it anyway, because it explains the process very well, and will help you to understand the rest of my answer.

这篇关于更改android中微调器上小三角形的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆