2015-10-20 169 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"/>