Android 2.2的微调看起来老的动作条 [英] Android 2.2 Spinner looks old in Actionbar

查看:129
本文介绍了Android 2.2的微调看起来老的动作条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 2.2的微调在我的动作条看起来很丑陋,下拉文本颜色相同的背景颜色。这使得文本无法读取。

on Android 2.2 the Spinner in my ActionBar looks really ugly and the dropdown text color is the same as the background color. This makes the text unreadable.

下面是相关code。

spinner = new Spinner(getSupportActionBar().getThemedContext());
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
(
    getSupportActionBar().getThemedContext(), 
    R.layout.sherlock_spinner_dropdown_item, 
    new String[]{"All", "Solved", "Unsolved"}
);
spinner.setAdapter(spinnerArrayAdapter);

Edit: I have added the below 3 lines for completeness.

menu.add("Display")
    .setActionView(spinner)
    .setShowAsAction(MenuItem.Show_AS_ACTION_ALWAYS);

下面是它看起来像在Android 4.2。这是我期望它看起来像在Android 2.2还。

Here is what it looks like on Android 4.2. This is what I expected it to look like on Android 2.2 also.

推荐答案

在创建 SpinnerArrayAdapter ,你应该使用 R.layout.sherlock_spinner_item ;那么你应该叫 setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item)适配器上。注意两个资源名称之间的区别。

When you create the SpinnerArrayAdapter, you should use R.layout.sherlock_spinner_item; then you should call setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item) on the adapter. Note the difference between the two resource names.

从样品code:

Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

有关您的code这将是:

For your code this would be:

spinner = new Spinner(getSupportActionBar().getThemedContext());
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
(
    getSupportActionBar().getThemedContext(), 
    R.layout.sherlock_spinner_item, 
    new String[]{"All", "Solved", "Unsolved"}
);
spinnerArrayAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);

这篇关于Android 2.2的微调看起来老的动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆