我正在使用以下代码更改应用程序主题:
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显示白色背景和白色文本。如何解决?
答案 0 :(得分:1)
请尝试:setInverseBackgroundForced(true)
答案 1 :(得分:1)
您正在使用默认的Android主题。这意味着操作系统将决定颜色。如果你自己设置颜色,你可能会遇到标准主题。
尝试自定义或使用您自己定义的主题。有关详细信息,请参阅以下主题。
答案 2 :(得分: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" />