0

このコードでアプリケーションのテーマを変更しています:

MainActivity.java:

setTheme(R.style.AppBlackTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

styles.xml:

<style name="AppTheme" parent="android:Theme.Light" />
<style name="AppBlackTheme" parent="android:Theme.Black" />

そして、AlertDialogを作成します。

    SimpleAdapter simpleAdapter=new SimpleAdapter(this, listItems, R.layout.templates_list_item, new String[] {"name","descr"}, new int[] {R.id.name,R.id.descr});
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setSingleChoiceItems(simpleAdapter, -1, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //...
            }
        });
alert.show();

しかし、Android 2.1では、このAlertDialogは白い背景と白いテキストで表示されます。それを修正する方法は?

4

3 に答える 3

1

してみてください:setInverseBackgroundForced(true)

于 2013-02-26T20:42:11.897 に答える
1

デフォルトの Android テーマを使用しています。これは、OS が色を決定することを意味します。自分で色を設定すると、標準テーマの邪魔になることがあります。

独自に定義したテーマをカスタマイズまたは使用してみてください。詳細については、次のトピックを参照してください。

AlertDialog のテーマを変更する方法

于 2013-02-26T20:43:35.740 に答える
0

今私はそれを行います:

値/styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="android:Theme.Light">
        <item name="alert_text_color">@android:color/black</item>
    </style>
    <style name="AppBlackTheme" parent="android:Theme.Black">
        <item name="alert_text_color">@android:color/black</item>
    </style>
</resources>

値-v11/styles.xml:

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light" >
        <item name="alert_text_color">@android:color/black</item>
    </style>
    <style name="AppBlackTheme" parent="android:Theme.Holo" >
        <item name="alert_text_color">@android:color/white</item>
    </style>
</resources>

値/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="customAttrs">
        <attr name="alert_text_color" format="reference" />
    </declare-styleable>
</resources>

およびレイアウト (templates_list_item):

<TextView
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="?attr/alert_text_color" />
于 2013-02-27T13:20:51.267 に答える