如何在小部件的右侧创建没有向下三角形的android微调器 [英] How to create android spinner without down triangle on the right side of the widget

查看:29
本文介绍了如何在小部件的右侧创建没有向下三角形的android微调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个屏幕,用户有很多项目要输入,因此屏幕空间非常宝贵.

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

我希望小部件在屏幕上的外观(在用户按下它之前)类似于 EditText 或 Spinner 右侧的 Spinner 小部件的左侧部分(没有正常的向下三角形).然后当用户按下小部件时,他/她将获得正常的 Spinner 选择对话框.

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.

是否有我可以更改的 Spinner 样式属性来实现此目的?

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

我一直无法看到这样的代码.

I have not been able to see code like this.

谢谢

推荐答案

你可以做的一件事就是从 android 代码库中获取 Spinner 的源代码,连同相关的布局和资源,并使用它们来创建您自己的自定义小部件(可能您只需要从布局中删除箭头并根据您的需要稍微调整代码).

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/values下创建一个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.

这篇关于如何在小部件的右侧创建没有向下三角形的android微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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