3

私はそれに基本的AutoCompleteTextViewであり、ArrayAdapterそれに縛られています。Android 4.* では問題なく動作しますが、2.3 ではドロップダウンをスクロールするたびに行がすべて黒でレンダリングされます。行をタップすると、ドロップダウン全体が正しくレンダリングされます。

以下のテキストでは、 TextView が を使用して生成されるときにinflate、背景色を白 (コメントアウトされた行) に設定すると、スクロールしても常に白が表示されますが、タップ選択効果 (行をシステムに変更して行をタップします) color) は機能しません。

ここでは actionbarsherlock を使用していますが、それが原因ではないことを願っています。何か案は?

スクリーンショット: http://i.imgur.com/gnugp.png

public class AutocompleteAdapter extends ArrayAdapter<String> implements Filterable {

public AutocompleteAdapter(Context context) {
    super(context, android.R.layout.simple_dropdown_item_1line);

    mInflater = LayoutInflater.from(context);
    mContext = context;
}

@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    final TextView tv;
    if (convertView != null) {
        tv = (TextView) convertView;
    } else {
        tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
        //tv.setBackgroundColor(tv.getResources().getColor(R.color.white));
    }

    tv.setText(getItem(position));
    return tv;
}
....
4

4 に答える 4

4

それはあなたのテーマが暗いからです..

Manifest.xml のテーマがライトの場合..つまり、

    <application
        android:label="@string/app_name"
        android:theme="@style/Theme.Light.NoTitleBar.Workaround" >

値フォルダーに2つのxmlファイルを追加することで機能するようになりました..

スタイル.xml

<resources>

    <style name="AppTheme" parent="android:Theme.Light" />
      <style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView">
    <item name="android:textColor">@android:color/primary_text_light</item>
    </style>
    <style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem">
        <item name="android:textColor">@android:color/primary_text_light</item>
    </style>
</resources>

テーマ.xml

<resources>
    <style name="Theme.Light.NoTitleBar.Workaround" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item>
        <item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item>
    </style>
</resources>

他に方法が見つかりませんでした...

于 2013-01-10T06:11:12.007 に答える
1

このように使用してみてください...

tv = (TextView) mInflater.inflate(android.R.layout.simple_spinner_item, parent, false);
于 2013-01-10T06:03:36.713 に答える
1

I believe, the DropDown background and TextColor depends on the Theme of your application or the default theme of the device.

Since, you said it worked fine on few devices(i had the same issue). Its always good to use a custom DropDownItem.

Instead of:

tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);

using simple_dropdown_item_1line use a custom TextView Layout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/text_dropDown"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:background="@color/white"
    android:padding="2dp"
    android:textColor="@color/text_light_grey"
    android:textSize="@dimen/text_medium" >
</TextView>
于 2013-01-10T05:55:16.513 に答える
1

この問題は、使用時のよく知られている問題に似ていますListView

http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html

解決策は属性を使用することcacheColorHintですが、 には属性が存在しないためAutoCompleteTextView、どのように設定しますか? 実際には、ドロップダウン メニューで設定する必要があります。

ドロップダウンにカスタム スタイルを適用します。

<item name="dropDownListViewStyle">@style/Widget.YourApp.DropDownListView</item>

に値を設定しますcacheColorHint

<style name="Widget.YourApp.DropDownListView" parent="android:Widget.ListView.DropDown">
    <item name="android:cacheColorHint">@android:color/transparent</item>
</style>
于 2013-06-18T12:30:38.627 に答える