2013-05-27 136 views
5

我試圖讓這個AlertDialog綠色的三個項目。問題是目前警報後面出現綠色背景,其中兩個項目不顯示爲綠色。我當前設置的AlertDialog的風格與此代碼:AlertDialog.Builder項背景顏色

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ListRow)); 

在我styles.xml,我有這樣的風格:

<style name="ListRow"> 
    <item name="android:background">@color/forest_green</item> 
    <item name="android:textSize">18sp</item> 
    <item name="android:textColor">@color/dialog_text</item> 
</style> 

enter image description here

+0

什麼反正這個代碼的問題是什麼? –

+0

不要在*主題*上使用'android:background'。沒有定義其背景的所有東西都是綠色的。你如何重寫'android:buttonBarStyle'和'android:buttonBarButtonStyle'呢? –

+0

你可以看看這些教程:http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/和http://www.materialdoc.com/alerts/ – noongiya95

回答

-1

使用styles.xml這樣

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="AlertDialogCustom" parent="@android:style/AlertDialog"> 
    <item name="android:textColor">#00FF00</item> 
    <item name="android:typeface">monospace</item> 
    <item name="android:textSize">10sp</item> 
</style> 

+3

是否在發佈之前嘗試過?這甚至不編譯... – moonlightcheese

+0

我有使用此獲取錯誤:錯誤:檢索父項的錯誤:找不到匹配給定名稱'@android:style/AlertDialog'的資源。 –

0

您可以設置自定義編程查看這樣的方式..

LayoutInflater inflater = getLayoutInflater(); 
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus()); 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(dialoglayout); 
builder.show(); 

創建您的佈局與綠色背景dialog_layout.xml。

0

這對我有用。他們都有背景。

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

builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome") 
     .setMessage("...") 
     .setPositiveButton("login", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(HomeActivity.this, LoginActivity.class); 
       startActivity(intent); 
      } 
     }).setNegativeButton("register", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) 
      { 
       Intent intent = new Intent(getApplicationContext(),RegisterActivity.class); 
       startActivity(intent); 
      } 
     }).show(); 
0

定義與Theme.AppCompat.Dialog.Alert作爲父母的對話風格:

<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert"> 
    <item name="android:background">@color/green</item> 
    ... 
</style> 

來源:http://www.materialdoc.com/alerts/