View中添加左可绘制对象

View中添加左可绘制对象

本文介绍了如何在Android的Spinner View中添加左可绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在Spinner中添加左可绘制对象,但是我没有找到任何合适的方法,因为您在EditText中使用android:drawableLeft="@drawable/password_drawable"做同样的事情.在Android的Spinner中是否有任何正确的方法来实现相同的目标.

在我的情况下,应该只保留我在屏幕快照中给出的此状态的可绘制状态,当用户单击微调器时,我不想在Spinner

我正在尝试没有这种属性的情况

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/edittext_border"
     />

我想要下面的截图

当前看起来像下面

当我设置Spinner的背景时,它看起来就像

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/selectone_drawable"
    android:entries="@array/select_type" />

预先感谢

解决方案

创建一个9色块图像并将其设置为Spinner的背景,然后添加一个左填充,可以解决问题.

Hello I am trying to add left drawable in Spinner but I didn't find any propery for this as you do same in EditText using android:drawableLeft="@drawable/password_drawable". Is there any correct way to achieve same in Spinner in Android.

Here in my case there should be left drawable only this state which I gave in the screenshot, when user click on the Spinner I don't want to have left drawable there in open drop down list in Spinner

I'm trying like this where there is no such attribute

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/edittext_border"
     />

I want something like below screenshot

Currently it is looking like below

and when I set the background of the Spinner then it looks like

<Spinner
    android:id="@+id/selectSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/sign_up_views_vertical_top_margin"
    android:background="@drawable/selectone_drawable"
    android:entries="@array/select_type" />

Thanks in advance

解决方案

Create a nine-patch image and set it as the background of the Spinner, then add a left padding, should do the trick.

这篇关于如何在Android的Spinner View中添加左可绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:33