如何在右侧的窗口小部件创建一个不倒三角的Andr​​oid微调创建一个、不倒、部件、窗口

2023-09-12 00:50:57 作者:她乡的春季。

我有,用户有许多项目的投入,使屏幕空间是在premium的屏幕。

I have a screen where the user has many items to input so screen space is at a premium.

欲小部件的屏幕上的外观(用户presses之前)是在右侧的类似于一个EditText或微调小部件的左部(没有进行正常倒三角)微调。然后,当用户presses小部件,他/她将得到正常的微调选择对话框。

I want the look of the widget on the screen (before the user presses it) to be similar to an EditText or the left portion of the Spinner widget (without the normal down triangle) on the right side of the Spinner. Then when the user presses the widget, he/she will get the normal Spinner selection dialog.

有一些微调样式属性我可以改变做到这一点?

Is there some Spinner style attribute I can change to accomplish this?

我一直没能看到code这样的。

I have not been able to see code like this.

感谢

推荐答案

有一件事你可以做的是采取微调的源$ C ​​$从安卓code C基,以及相关的布局和资源,并利用它们来创建自己的自定义窗口小部件(可能你只需要从布局中删除的箭头,并调整了codea的一点取决于你的需求)。

One thing you can do is take Spinner's source code from android code base, together with related layouts and resources, and use them to create your own custom widget (probably you will only need to remove the arrow from the layout and tweak the code a little depending on your needs).

编辑: 你说得对,下面这个职位它实际上是非常简单的:)你必须做两件事情。 首先,创建下RES /值的styles.xml文件,打开它,并添加以下内容:

You're right, following that post it was actually really simple :) You have to do two things. First, create a styles.xml file under res/values, open it and add the following:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style parent="@android:style/Widget.Spinner" name="SpinnerAsEditText">
        <item name="android:background">@android:drawable/edit_text</item>
    </style>
</resources>

接下来,在你的布局,加上微调是这样的:

Next, in your layout, add the Spinner like this:

<Spinner style="@style/SpinnerAsEditText" anyOtherAttributeYouNeed="..."></Spinner>

就是这样,现在的微调会看起来像一个普通的EditText,没有这种无用的和恼人的向下箭头。

That's it, now the spinner will look like a plain EditText, without that unuseful and annoying down arrow.