2010-01-07 92 views
4

我該如何着手改變這個對話框的框架顏色?我嘗試了一堆東西,沒有任何工作。改變窗框的顏色

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">    
    <item name="android:windowNoTitle">true</item> 
    </style> 
</resources> 
+0

@Alex Volovoy:我只是想對話框窗口的邊框設置爲不同的顏色。沒有這個屬性嗎?比如,android:frameColor或者其他什麼?那當然太容易了。 :) – cakeforcerberus 2010-01-07 02:25:13

+0

也看看這個(關於「九貼片」圖像):http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch – 2011-06-14 15:59:21

回答

11

你的意思是白色框?我認爲這是9-patch drawable的一部分,您可以查看SDK.DF如何在SDK_FOLDER \ platforms \ android-sdkversion \ data \ res \ values中構建Theme.Dialog 然後styles.xml和themes.xml

As我說過,白色框架是背景圖像的一部分。它的panel_background.9.png所以如果你想改變框架 - 你需要不同的背景圖片+需要覆蓋樣式設置它。

<item name="android:windowBackground">@android:drawable/panel_background</item> 

,你就需要定義將從Theme.Dialog導出一個樣式,如果你把在styles.xml像

<style name="NewBorderDialogTheme" parent="android:Theme.Dialog"> 
<item name="android:windowBackground">@drawable/your_drawable</item> 
</style> 
有這個

<item name="android:windowBackground">@drawable/your_drawable</item> 

所以

放置新的繪圖並將您的活動設置爲新主題 - 您應該看到新的邊框

+0

明白了。謝謝。 – cakeforcerberus 2010-01-07 02:50:20

+0

它不適合我,它只是顯示未修改對話框後面的圖像。我錯過了什麼? – 2011-06-14 09:55:00

+0

http://stackoverflow.com/questions/3310412/progressdialog-nesting-inside-of-another-blank-dialog – 2011-06-14 15:58:24

0

如果您想要做到這一點編程方式,嘗試下面的代碼:

你要做的:

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