更改对话框微调框的popupbackground颜色

问题描述:

我想更改我的对话框微调框的popupBackground颜色。更改对话框微调框的popupbackground颜色

在我activity.xml

<Spinner 
        android:id="@+id/mCategorySpinner" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@id/textView7" 
        android:entries="@array/recipeCategory" 
        android:spinnerMode="dialog" 
        android:popupBackground="@color/colorPrimary" 
        android:textAlignment="center" /> 

在我activity.java

categorySpinner=(Spinner) findViewById(R.id.mCategorySpinner); 
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.recipeCategory, android.R.layout.simple_spinner_item); 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     categorySpinner.setPrompt("Choose category"); 
     categorySpinner.setAdapter(new NothingSelectedSpinnerAdapter(
       adapter, 
       R.layout.category_spinner_row_nothing_selected,    
       this)); 

什么,如果我改变XML android:popupBackground发生,它仍然是默认的白色。
但是,如果我改变背景它的作品,但它不是对话框的背景。

+0

https://*.com/questions/31425697/spinner-popup-background-color-issue –

+1

这里阅读:https://*.com/questions/8922924/how-to-change-android -spinner-popupbackground –

你可以改变背景颜色和下拉图标喜欢做这样

第1步:在绘制文件夹进行了微调的背景称为background.xml文件。

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@android:color/transparent" /> 
    <corners android:radius="5dp" /> 
    <stroke 
     android:width="1dp" 
     android:color="@color/darkGray" /> 
</shape> 

第2步:现在申请此背景下你的微调在XML文件中

android:background="@drawable/background" 
+0

可绘制文件夹中的XML资源就像图像一样访问,不需要在名称后面添加'.xml'。这实际上导致它不被发现。 – Zoe

1.使用spinner_selector.xml

要显示的颜色变化的

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

2.添加样式

将其添加到样式中,您可以在其他位置使用它。

<style name="spinner_style"> 
    <item name="android:background">@drawable/spinner_selector</item> 
</style> 

3.增加它的XML代码

使用它作为微调的背景。

<Spinner 
    android:id="@+id/mCategorySpinner" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/textView7" 
    android:entries="@array/recipeCategory" 
    android:spinnerMode="dialog" 
    style="@style/spinner_style" 
    android:textAlignment="center" /> 
+0

没有说明。现在有一些说明我删除了downvote。请记住,并非每个在将来阅读此文的人都确切地知道所有内容,解释它非常重要。它仍然需要一个更好的解释,但现在它已经足够好了,它不会被低估 – Zoe

+0

'@ drawable/spinner_press'和'@ drawable/spinner'怎么样? – Chris

+0

我将它更改为彩色。如果按下,颜色将会改变。@ Chris – KeLiuyue