如何更改微调器弹出窗口的背景颜色?

2024-04-14移动开发问题
7

本文介绍了如何更改微调器弹出窗口的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试设置微调器弹出窗口的背景颜色,但我尝试过的所有操作都无法正常工作.

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 which 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添加一个默认状态是可以的,但是spinner主控件用那个背景颜色显示项目,我不想要那个.

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),并且属性 android:popupBackground 不存在.

PS: I'm using API level 10 (2.3.3) and the attribute android:popupBackground doesn't exist.

推荐答案

以上解决方案都不适合我.

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;
}

这篇关于如何更改微调器弹出窗口的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Cocos2d 播放2种不同的背景音乐文件或循环播放效果
Cocos2d play 2 different background music files or loop playEffect(Cocos2d 播放2种不同的背景音乐文件或循环播放效果)...
2024-08-12 移动开发问题
30

观看 Game Center 屏幕(排行榜、成就)时,如果在 iOS7 中后台运行 cocos2d 2.1 应用程序会崩
Crash if backgrounding cocos2d 2.1 app in iOS7 while watching Game Center screens (leaderboard, achievement)(观看 Game Center 屏幕(排行榜、成就)时,如果在 iOS7 中后台运行 cocos2d 2.1 应用程序会崩溃)...
2024-08-12 移动开发问题
2

cocos2d如何快速绘制背景?
How to draw a background fast in cocos2d?(cocos2d如何快速绘制背景?)...
2024-08-12 移动开发问题
5

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d中如何在CCLabelTTF中设置背景色
How to set background color in CCLabelTTF in cocos2d(cocos2d中如何在CCLabelTTF中设置背景色)...
2024-08-12 移动开发问题
5

在 cocos2d 中加载大背景图片
Loading large background images in cocos2d(在 cocos2d 中加载大背景图片)...
2024-08-12 移动开发问题
3