Android 自定义对话框中复选框控件的文本可以';在某些安卓设备中无法显示

Android 自定义对话框中复选框控件的文本可以';在某些安卓设备中无法显示,android,Android,我使用以下代码创建并打开一个自定义对话框,它在android 4.2.2中运行良好,但在android 2.3.6中无法显示复选框控件的文本 我发现在安卓4.2.2中,复选框控件的文本是黑色的,对话框的背景色是白色的,所以它是可以的,但是在安卓2.3.6中,对话框的背景色是黑色的,所以它是不好的 我该怎么办 sms\u dialog.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="h

我使用以下代码创建并打开一个自定义对话框,它在android 4.2.2中运行良好,但在android 2.3.6中无法显示复选框控件的文本

我发现在安卓4.2.2中,复选框控件的文本是黑色的,对话框的背景色是白色的,所以它是可以的,但是在安卓2.3.6中,对话框的背景色是黑色的,所以它是不好的

我该怎么办

sms\u dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <CheckBox
        android:id="@+id/chNoDisplayAgain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"        
        android:text="" />

</LinearLayout>

使用文本颜色和背景颜色进行尝试,如下所示

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertial"
android:background="@android:color/white"
android:padding="10dp" >
<CheckBox
    android:id="@+id/chNoDisplayAgain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" 
    android:textColor="@android:color/black"
    android:text="" /></LinearLayout>

    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customDialogTheme));

AlertDialog.Builder=新建AlertDialog.Builder(新的ContextThemeWrapper(this,R.style.customDialogTheme));
创造你喜欢的风格


#000000
#ffffff

API 11之前版本的唯一真正解决方案是用XML创建整个布局。您只需要为标题添加TextView,在其下方添加另一个用于消息的TextView,以及按钮


然后整个布局将使用您为应用程序选择的默认主题。如果需要,也可以设置样式。

我使用这行代码,它工作正常。它将使对话框背景颜色与11+api上的颜色相同

alertDialogBuilder.setInverseBackgroundForced(true);
alertDialogBuilder.create();

在项目中添加文件夹

res/layout-v10
然后创建文件“sms_dialog.xml”,并定义代码和文本颜色:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <CheckBox
        android:id="@+id/chNoDisplayAgain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@android:color/white"
        android:text="" />
</LinearLayout>

这样,复选框文本的颜色将仅适用于android API 10(2.3.3)-
2.3.7). Android将在剩下的时间里使用“res/layout”中的布局文件。

我会像santhosh建议的那样做,但有点扭曲。 我想: 为新旧android版本创建自定义对话框样式 将这些带有样式的xml文件放在两个文件夹中:values和values-v11

特殊文件夹名values-v11有一个所谓的限定符,它告诉android将此资源用于蜂窝及以上设备。 因此,通过这种方式,您可以在不更改java代码的情况下,一次查找较旧的设备,另一次查找较新的设备。
如果你喜欢这类东西,请查看HoloEverywhere库。

使用scrollview而不是linear。。你可以检查api版本是否为2.3.6或更低,然后设置复选框的颜色其他内容?谢谢!但这并不好。背景色为半白半黑u也可以应用您的主题…创建自定义主题将背景色设置为白色,文本颜色设置为黑色,并在AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder中提供此主题(此,主题);谢谢你能展示一些关于创建和应用对话主题的示例代码吗?谢谢!但是您的代码有一个错误“检索项的父项时出错:未找到与给定名称“@android:style/AlertDialog”匹配的资源”。API 11添加了在构造函数中添加主题的功能,这也是在他们添加较新的AlertDialogs使用的Holo主题时添加的。
res/layout-v10
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <CheckBox
        android:id="@+id/chNoDisplayAgain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@android:color/white"
        android:text="" />
</LinearLayout>