0

我为 AlertDialog 创建了一个自定义布局,它工作正常,但是我的布局的文本样式有问题。

这是我的 alertDialog 的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="match_parent"
    android:layout_height="match_parent"      
    android:orientation="vertical" >

    <TextView
        android:id="@+id/namedialoglable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/profilename" />

    <EditText
        android:id="@+id/namedialoginput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/namedialoglable"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:selectAllOnFocus="true"
        android:text="@string/defaultname" >

        <requestFocus />
    </EditText>

</RelativeLayout>

问题是默认 AlertDialog 中的文本是白色的,而在我的自定义对话框中是黑色的。我只想使用与其他 AlertDialog 相同的颜色。

怎么做?

编辑 要更清楚:我想保持父文本颜色,而不是强制我的自定义对话框颜色为白色。我认为 AlertDialog 使用系统颜色,所以我的警报需要保持相同的颜色

4

2 回答 2

0

好吧,就我而言,我找到了另一个解决方案。由于我只需要在对话框中输入一条消息和一个输入文本,因此最好的解决方案是创建一个只有一个 EditText 的布局,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="match_parent"
    android:layout_height="match_parent"      
    android:orientation="vertical" >

    <EditText
        android:id="@+id/namedialoginput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"        
        android:layout_marginTop="24dp"
        android:ems="10"
        android:selectAllOnFocus="true"
        android:text="@string/defaultname" >

        <requestFocus />
    </EditText>

</RelativeLayout>

对于消息文本,使用构建器方法:setMessage:

    builder.setView(content)
        .setTitle("Profile Name")
        .setMessage(R.string.profilename);

这样,我确信我会保留其他对话框格式。

于 2013-05-14T20:50:29.817 回答
0

你为什么不直接申请:

android:textColor="@android:color/white"

Views你想要的文字颜色。

还要查看样式和主题以实现您想要的:

http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles

于 2013-05-14T18:03:09.577 回答