微调视图。选择不工作 [英] Spinner view; selector not working

查看:180
本文介绍了微调视图。选择不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

微调XML:

<Spinner
        android:id="@+id/sort_by_spinner"
        android:layout_marginLeft="40dip"
        android:layout_marginRight="40dip"
        android:layout_marginBottom="10dip"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/title_bar"
        android:drawSelectorOnTop="true"
        android:dropDownSelector="@drawable/spinner_selector"
    />

我已经使用 Android的尝试:背景= ... 购买本身以 dropDownSelector ,有和没有 listSelector = ...; 带和不带 listItemDropDownSelector = ... 所有排列drawSelectorOnTop

I've tried using android:background=... buy itself, with dropDownSelector, with and without listSelector=...; with and without listItemDropDownSelector=... and all permutations with drawSelectorOnTop

spinner_selector:

spinner_selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/app_tint"/>
        </shape>
    </item>
    <item 
        android:state_selected="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/app_tint"/>
        </shape>
    </item>
</selector>

我总是得到默认的橙色。我读过这个帖子众多;只是不能让它发生。我要支持V10以上。缺少了什么?

I always get the default orange color. I've read numerous posts on this; just can't get it to happen. I have to support v10 and up. What's missing?

推荐答案

尝试,因为:

<Spinner         
    android:id="@+id/sort_by_spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="@dimen/space"
    android:background="@drawable/selection_normal"
    android:dropDownSelector="@drawable/list_item_selector"
    android:spinnerMode="dropdown" />

和list_item_selector为

and the list_item_selector as

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_selected="true" android:drawable="@color/app_tint"></item>
    <item android:state_pressed="true" android:drawable="@color/app_tint"></item>
    <item android:drawable="@color/white"></item>
</selector>

selection_normal是微调的任何图像,你可以忽略它,如果没有必要的。

selection_normal is any image for the spinner, you can ignore it if not needed.

为了设置突出项目的列表行触及/点击做到以下几点:

In order to set highlight the list row of the item touched / clicked do the following:

getDropDownView 而不是 getView 在飞旋的适配器使用code设置选择方法:

in the getDropDownView instead of getView method in the spinner's adapter set the selector using the code:

view.setBackgroundResource(R.drawable.list_item_selector)

或使用视图的的setBackground 方法。

这篇关于微调视图。选择不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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