Android的:如何设置微调选择自己的图像/图标? [英] Android: How to set spinner selector to own image/icon?

查看:91
本文介绍了Android的:如何设置微调选择自己的图像/图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找和测试设置自己的图像/图标的微调,但我得到的错误。

I have searching and testing to set my own image/icon in a Spinner but i get error.

我有alrady与造型设定背景图片,但随后没有再显示在右侧的微调图标。

I have alrady with styling set background image but then the spinner icon on the right side not shows anymore.

当我不喜欢我找到了这样一个例子:

When i do like i find a example of like this:

<Spinner style="@style/Spinner" android:spinnerSelector="@drawable/myspinner_selector" />

这里是myspinner_selector.xml:

And here is the myspinner_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_first="true"
   android:drawable="@drawable/arrowdown"
   />    
<item android:state_middle="true" 
   android:drawable="@drawable/arrowdown"
   />       
<item android:state_last="true"
   android:drawable="@drawable/arrowdown"
   />   
<item android:state_single="true"
   android:drawable="@drawable/arrowdown"
   />

但它是在第一个 XML 的微调我得到这个错误:

But it is in the first XMLfor spinner I get this error:

No resource identifier found for attribute 'spinnerSelector' in package 'android' `main.xml`

所有的例子我能在互联网上找到使用微调选择这样的造型,但我不能让它的工作,并不能找到 spinnerSelector 在<参考指南A HREF =htt​​p://developer.android.com相对=nofollow> developer.android.com 无论是。

推荐答案

我不力让德答案改变微调图像,但你可以做到这一点。

I dint get teh answer for changing the spinner image but you can do it..

1.设置微调高度和宽度0dp

1.Set the spinner height and width to 0dp

2.创建在这样的微调的onclick监听通话点击诉权按钮

2.Create a button in the onclick listener call click actio of the spinner like this

button.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        spin.performClick();
    }
});

3.change按钮文本相匹配的微调文本。

3.change the button text to match the spinner text.

public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    button.setText(items[position]);
}

4.Now您可以轻松地更改按钮图像!

4.Now you can change the image of the button easily!

这篇关于Android的:如何设置微调选择自己的图像/图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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