2015-10-20 192 views
1

我正在尝试在微调器中自定义箭头图像。这里是我的代码:在Android微调器中设置自定义下拉箭头

LayoutInflater inflater = LayoutInflater.from(context); 
spin = (Spinner) inflater.inflate(R.layout.spinner, null); 
adapter = new ArrayAdapter<Choice>(context, R.layout.nitro_spinner_item, choicesArr); 
adapter.setDropDownViewResource(R.layout.multiline_spinner_dropdown_item); 
spin.setAdapter(adapter); 

和R.layout.nitro_spinner_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@android:id/text1" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:drawableEnd="@drawable/ic_action_acf" 
     android:ellipsize="marquee" 
     android:singleLine="true" 
     android:textAlignment="inherit"/> 

但这里是我得到: enter image description here

我看到我的自定义图像,与普通的Android沿下拉箭头。我用这里的答案作为参考:https://stackoverflow.com/a/30336734/1642002。如果我重写了文本视图,股票下拉图像来自哪里?

+0

http://stackoverflow.com/questions/25028202/android-add-arrow-image-to-spinner –

+0

也许是部分背景。如果您将@ android:background =“@ android:color/transparent”'添加到xml中,会发生什么情况 – Blackbelt

+0

@Blackbelt:我试过了,箭头不能是textview本身的一部分。 – regretoverflow

回答

0

只需设置Spinner控件的透明背景:

<Spinner 
     android:id="@+id/spinner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent"/>