2010-12-08 64 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(); 
    } 
}); 
相关问题