2013-05-14 75 views
0

我创建了一个自定义布局的AlertDialog,并能正常工作, 但我有我的布局的文本样式的问题。的Android:自定义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使用系统的颜色,所以我警觉需要保持同一色性

回答

0

为什么不会你只是适用于:

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

Views你想,而文本颜色。

还应考虑风格和主题,实现您wnat什么:

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

+0

但我不希望它是白色的,更清楚,我想其他的对话框相同的颜色。例如,在安卓4.0的对话框是白加黑的文字,我想保持色彩的父类! – Ivan 2013-05-14 18:23:55

+0

那么你可能要考虑的风格和主题:http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles – 2013-05-14 18:28:02

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); 

这样,我确信我保持其他对话框的格式。