2010-01-07 97 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(); 
    } 
});