2013-05-14 79 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); 

這樣,我確信我保持其他對話框的格式。