2010-12-08 61 views

回答

1

你在anddev.org上有一些線索。基本想法是擴展默認主題並將其用於您的活動中。特別是,你需要擴展Theme.Dialog風格。

+0

謝謝哥們說真的是有用的歡呼聲,kariyachan – DroidBot 2010-12-08 12:25:47

1

是否可以命名您用於測試的設備?可能它們可能包含自定義的Android版本,因此對話框顏色會發生變化。您可以保持原樣,因爲您的構建將使用設備可用的默認樣式,其他嘗試設置樣式可避免此行爲。

1

通過設置對話框主題將活動用作對話框。然後,您可以用自己的背景和顏色誇大自己的佈局。

1

改變DialogBox的顏色,並用AlertDialog做更多的事情。

你要做的:

AlertDialog是您的屏幕上可見,OnShowListener被調用。因此,通過添加dialog.setOnShowListener(this),您將能夠自定義您的AlertDialog

代碼:

// Create AlertDialog 
AlertDialog.Builder adb = new AlertDialog.Builder(context1); 
    adb.setTitle(context1.getString(R.string.app_name)) 
    .setMessage(message) 
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 

     } 
}); 
AlertDialog dialog = adb.create(); 

// Make some UI changes for AlertDialog 
dialog.setOnShowListener(new DialogInterface.OnShowListener() { 
    @Override 
    public void onShow(final DialogInterface dialog) { 

     // Add or create your own background drawable for AlertDialog window 
     Window view = ((AlertDialog)dialog).getWindow(); 
     view.setBackgroundDrawableResource(R.drawable.your_drawable); 

     // Customize POSITIVE, NEGATIVE and NEUTRAL buttons. 
     Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE); 
     positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor)); 
     positiveButton.setTypeface(Typeface.DEFAULT_BOLD); 
     positiveButton.invalidate(); 

     Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE); 
     negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor)); 
     negativeButton.setTypeface(Typeface.DEFAULT_BOLD); 
     negativeButton.invalidate(); 

     Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL); 
     neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor)); 
     neutralButton.setTypeface(Typeface.DEFAULT_BOLD); 
     neutralButton.invalidate(); 
    } 
}); 
相關問題