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

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

问题描述



如何我改变小三角形的颜色在旋转器的右下角,如图所示?
现在显示默认的灰色。像这样



>

解决方案

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






以下是示例XML文件:



自定义颜色:

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

自定义微调风格:

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

<! - 使用http://android-holo-colors.com - >
< resources xmlns:android =http://schemas.android.com/apk/res/android>

< style name =SpinnerAppThemeparent =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 =SpinnerDropDownItemAppThemeparent =android:Widget.DropDownItem.Spinner>
< item name =android:checkMark> @ drawable / apptheme_btn_radio_holo_light< / item>
< / style>
< / resources>

自定义应用程序主题:

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

<! - 使用http://android-holo-colors.com - >
< resources xmlns:android =http://schemas.android.com/apk/res/android>

< style name =AppThemeparent =@ style / _AppTheme/>

< style name =_ AppThemeparent =Theme.AppCompat.Light>

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

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

< / style>

< / resources>






正如你所看到的,



以下是您要更改的三角形的具体属性:

 <?xml version =1.0encoding =utf-8?> 
<! - 版权所有(C)2010 Android开源项目

根据Apache许可证2.0版(许可证)授权;
除非符合许可证的要求,否则不得使用此文件。
您可以通过以下方式获取许可证的副本:

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

除非适用法律要求或同意以书面形式,根据许可证分发的软件
按原样基础分发,不含任何明示或暗示的担保或条件。
请参阅许可证管理许可权的特定语言和
限制。
- >

< 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 =falseandroid:state_focused =true
android:drawable =@ drawable / apptheme_spinner_focused_holo_light/>
< item android:drawable =@ drawable / apptheme_spinner_default_holo_light/>
< / selector>

我不认为这是正确的地方完全列出每个文件,因为你可以 应用程序,以便所有旋转器都更新为自定义风格。



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





我建议你阅读它,因为它解释了这个过程,并且将帮助你了解我的其余回答。


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

解决方案

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.


Here are the example XML files:

Custom Color:

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

Custom Spinner Style:

<?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>

Custom Application Theme:

<?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.

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天全站免登陆