工具栏中的android微调框上的翻转箭头 [英] Flip arrow on android spinner in toolbar

查看:97
本文介绍了工具栏中的android微调框上的翻转箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕底部的工具栏中有一个微调器,但是微调器旁边的箭头指向下方,这是违反直觉的.是否有任何快速的方法可以将箭头翻转为向上指向?

I have a spinner in a toolbar at the bottom of the screen, but the arrow next to the spinner points down, which is counterintuitive. Is there any quick way to flip the arrow to point upwards instead?

如果有帮助,则微调器的定义如下:

If it helps, the spinner is defined as follows:

<Spinner
    android:id="@+id/spinner_floors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

行布局仅为android.R.layout.simple_spinner_dropdown_item.

另一方面,展开微调框时,是否可以将字体颜色更改为白色而不影响字体颜色?

On another note, is there any way to change the font color to white without affecting the font color when the spinner is expanded?

我设法使用此图片的背景,所以现在的代码是

I managed to switch the color of the text using this answer. I also switched the background for this image so that now the code is

<Spinner android:id="@+id/spinner_floors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_arrow_drop_up_white_24dp" />

现在看起来像这样:

如何将按钮向右移动?

注意:我正在使用API​​级别为23的Android棉花糖

Note: I'm using Android Marshmallow, API level 23

推荐答案

微调框的默认背景是

The default background of a spinner is a 9-patch drawable, so it can scale accordingly. If you want to invert the arrow you have to copy the drawable and invert it manually.

在这里,我使用了在Lollipop 1 上找到的微调框的背景,并将其垂直翻转:

Here I took the background of the spinner found on Lollipop1 and flipped it vertically:

您可以将其复制并以9补丁的形式保存到drawable-xxxhdpi文件夹中,即扩展名为.9.png(而不仅仅是.png).

You can copy that and save it into the drawable-xxxhdpi folder as a 9-patch, i.e. with the extension .9.png (not just .png).

1 [android-sdk]/platforms/android-22/data/res/drawable-xxxhdpi/spinner_mtrl_am_alpha.9.png

自棉花糖以来,默认背景是XML可绘制对象(选择器和矢量可绘制对象).如果您只想支持Android 6.0及更高版本,则可以从Ansroid SDK复制并进行修改,使其垂直翻转.

Since Marshmallow, the default background is an XML drawable (selector and vector drawable). If you only want to support Android 6.0 and newer you can copy that from the Ansroid SDK and modify it such that it is vertically flipped.

您可以在 [android-sdk]/platforms/android-23/data/res/drawable/目录中找到该可绘制对象.它名为spinner_background_material.xml,并取决于control_background_40dp_material.xmlic_spinner_caret.xml.

You can find the drawable in the [android-sdk]/platforms/android-23/data/res/drawable/ directory. It's named spinner_background_material.xml and depends on control_background_40dp_material.xml and ic_spinner_caret.xml.

这篇关于工具栏中的android微调框上的翻转箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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