风格android微调器

dut*_*utt 23 android

我试图让我的Android应用程序更时尚,并取得了一些进展,但微调下拉正在给我带来麻烦.我有截图给你看问题:

如何摆脱白色背景

我想要的是背景中的白色框是透明的,就像在后面屏幕上的灰色覆盖图一样,在下拉屏幕之外的屏幕的其余部分.

Android 4.0,API 15,如果我没记错的话.

按照要求,这是我到目前为止的工作方式.这些是我认为相关的片段,但我可能错过了一些东西.

这是微调器的xml:

<Spinner
    android:id="@+id/edit_countrySpinner"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:entries="@array/edit_countryArray"
    android:gravity="center"
    android:prompt="@string/country_prompt" />
Run Code Online (Sandbox Code Playgroud)

在我的values/style.xml中.如果我在这里更改背景的颜色,对话框中的背景会发生变化,但所有其他背景也会发生变化.我还没弄清楚如何在下拉对话框中改变背景.

<style name="appcin" parent="@android:style/Theme.NoTitleBar.Fullscreen">
    <item name="android:spinnerStyle">@style/spinnerStyle</item>
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item> -->
    <item name="android:background">#FFFFFF</item>
</style>
<style name="spinnerStyle">
    <item name="android:background">@drawable/pink_white_dropdown</item>
    <item name="android:clickable">true</item>
</style>
<style name="SpinnerItem">
    <item name="android:textColor">#993399</item>
    <item name="android:background">@drawable/pink_white_dropdown</item>
    <item name="android:maxHeight">10dip</item>
</style>
<style name="SpinnerDropDownItem">
    <item name="android:textColor">#993399</item>
    <item name="android:background">#FFFFFF</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我已经尝试将此添加到应用主题,但它们没有任何区别,背景仍然是白色的.

<...theme....>
   <item name="android:dropDownListViewStyle">@style/DropDownStyle</item>
   <item name="android:dropDownSpinnerStyle">@style/DropDownStyle</item>
   <item name="android:dropDownSelector">@style/DropDownStyle</item>
</... theme ...>
<style name="DropDownStyle">
    <item name="android:background">#FFF000</item>
    <item name="android:popupBackground">#FFF000</item>
    <item name="android:cacheColorHint">#FFF000</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在drawable/pink_white_dropdown中,只显示所有案例的相同图像.pink_white_arrow是我制作的9patch图像.有很多指南,这是我在谷歌上30秒发现的指南.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:state_enabled="true"
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_window_focused="false" android:state_enabled="false"
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_pressed="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_pressed="false" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_focused="true" android:state_enabled="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_enabled="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_focused="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item 
      android:drawable="@drawable/pink_white_arrow"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

在这些文件中的某个地方,我认为某些东西应该是透明的,但我不知道在哪里.

Gun*_*son 50

删除SpinnerStyle背景属性.

删除这个:

<style name="spinnerStyle">
    <item name="android:background">@drawable/whitish_rectangle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是绘制背景白色矩形的原因.

基于您问题中的代码,这里有一个关于如何为Spinner设置样式的基本示例:

styles.xml文件为SpinnerItem和设置样式SpinnerDropDownItem:

<resources>
    <style name="customtheme" parent="@android:style/Theme.Light">
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
    </style>
    <style name="SpinnerItem">
        <item name="android:textColor">#993399</item>
        <item name="android:background">@drawable/my_rectangle</item>
    </style>
    <style name="SpinnerDropDownItem">
        <item name="android:textColor">#993399</item>
        <item name="android:background">@drawable/my_rectangle</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

为了测试,我创造了一个鲜艳的可绘制形状,称为my_rectangle.xml.用您自己的drawable替换它:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ff0000" />
    <stroke
        android:width="1dp"
        android:color="#888888" />
</shape>
Run Code Online (Sandbox Code Playgroud)

添加SpinnerActivity's布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:padding="40dip">
    <Spinner
        android:id="@+id/edit_countrySpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/location_names"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这会产生:

在此输入图像描述

在背景中没有白色方块.