我怎样才能改变一个微调弹出的背景颜色

我怎样才能改变一个微调弹出的背景颜色

本文介绍了我怎样才能改变一个微调弹出的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个微调弹出,但一切我试过没有正常工作的背景颜色。

I'm trying to set the background color of a spinner popup but everything I've tried didn't work properly.

这是微调控件:

<Spinner
  android:id="@+id/myspinner"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="@null"
  android:drawSelectorOnTop="true" />

当我点击它,它显示了一个白色背景上弹出,我想改变这种状况。

When I click on it, it shows a popup with a white background, and I want to change that.

在XML行至极我用填充弹出窗口:

The xml line wich I use to populate the popup is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/list_selector"
  android:paddingBottom="@dimen/padding_medium"
  android:layout_marginBottom="@dimen/padding_medium"
  android:orientation="vertical">

  ..........

</RelativeLayout>

和绘制背景list_selector.xml:

and the drawable background list_selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- Pressed -->
  <item
    android:state_pressed="true"
    android:drawable="@color/green" /> <!--  @drawable/tab_press -->

  <!-- Selected -->
  <item
    android:state_selected="true"
    android:drawable="@color/green" /> <!--  @drawable/tab_press -->

</selector>

添加默认状态,以上面的XML是好的,但微调主控显示与背景颜色的项目,我不希望出现这种情况。

Adding a default state to the above xml is ok, but the spinner main control shows the item with that background color, and I don't want that.

另一件事我已经试过是设置应用程序的背景颜色为黑色styles.xml

Another thing I've tried is to set the application background color to black in styles.xml

<style name="AppTheme" parent="android:Theme.Light">
     <item name="android:background">#000000</item>
     <item name="android:textColor">#FFFFFF</item>
     <item name="android:typeface">sans</item>
</style>

这将覆盖在弹出的背景下也是如此,但它有不良的附带影响。有没有办法做到这一点的一个简单的方法?

That overrides the popup background too, but it has undesirable collateral effects. Is there any way to accomplish this in a simple way?

谢谢!

PS:我使用的API等级10(2.3.3)和属性机器人:popupBackground 不存在

推荐答案

以上都不是解决办法为我工作。

None of the above solutions worked for me.

将溶液在写在传递给旋转器一个不同的实施方法中getDropDownView以显示不同的布局与自定义颜色适配器:

The solution was writing in the adapter passed to the spinner a different implementation in the method getDropDownView to display a different layout with custom colors:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View vista = convertView;

    // layout for spinner widget

    if (vista==null) {
        LayoutInflater inflater = actividad.getLayoutInflater();
        vista = inflater.inflate(R.layout.fila_colores_spinner, null);
    }

    return vista;
}

@Override
public View getDropDownView(int position, View convertView,ViewGroup parent) {
    View vista = convertView;

    //layout for spinner popup

    if (vista==null) {
        LayoutInflater inflater = actividad.getLayoutInflater();
        vista = inflater.inflate(R.layout.fila_colores_spinner_popup, null);
    }

    return vista;
}

这篇关于我怎样才能改变一个微调弹出的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:34