Android 2.2的微调看起来老的动作条动作、Android

2023-09-06 01:19:34 作者:低调,诠释不了我的高傲

在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);