styles.xml

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

import android.app.AlertDialog;import android.content.Context;import android.content.res.TypedArray;import android.content.res.Resources.Theme;import  android.graphics.PorterDuff;import android.graphics.drawable.Drawable;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.ImageView;public class MyColorDialog  extends AlertDialog{ private static int NONE = -1;     private int tint = NONE;       /**      * @param context     * @param theme     */      protected MyColorDialog(Context context) {        super(context);        init();           }      /**    * @param context    * @param theme     */   protected MyColorDialog(Context context, int theme) {       super(context, theme);      init();    }        /**     *     */    private void init() {            final Theme theme = getContext().getTheme();       final TypedArray attrs = theme.obtainStyledAttributes(new int[] { android.R.attr.tint });      tint = attrs.getColor(0, NONE);   }@Overridepublic void show() {// TODO Auto-generated method stubsuper.show(); setTint(tint);}public void setTint(int tint) {// TODO Auto-generated method stub this.tint = tint; android.graphics.PorterDuff.Mode mode = PorterDuff.Mode.SRC_ATOP;                    final Drawable d =  this.getWindow().getDecorView().getBackground();                         d.mutate().setColorFilter(tint, mode);                    }        /**     * @param button     */    public void setCancelButton(Button button) {       button.setOnClickListener(new View.OnClickListener() {           @Override         public void onClick(View v) {            cancel();          }           });    }        /**     * @param button     */    public void setPositiveButton(Button button) {       button.setOnClickListener(new View.OnClickListener() {           @Override          public void onClick(View v) {             dismiss();          }           });    }          public static class Builder extends AlertDialog.Builder {       private MyColorDialog dialog;             public Builder(Context context) {          super(context);                    dialog = new MyColorDialog(context);       }       public Builder(Context context, int theme) {          super(context);          dialog = new MyColorDialog(context, theme);       }             @Override       public MyColorDialog create() {          return dialog;       }        @Override       public Builder setMessage(CharSequence message) {          dialog.setMessage(message);          return this;       }        @Override       public Builder setTitle(CharSequence title) {          dialog.setTitle(title);          return this;       }        @Override       public Builder setPositiveButton(CharSequence text,             OnClickListener listener) {          dialog.setButton(BUTTON_POSITIVE, text, listener);          return this;       }           @Override          public Builder setIcon(int iconId) {             dialog.setIcon(iconId);             return this;          }     }}

使用

new MyColorDialog.Builder(this, R.style.OrangeDialogTheme).setPositiveButton("Dismiss", null).setTitle("Warning").setMessage("adhuhfdu").create().show();

<?xml version="1.0" encoding="utf-8"?> <resources>    <color name="red_tint">#88FF0000</color>    <color name="blue_tint">#880000FF</color>    <color name="yellow_tint">#88FFFF00</color>    <color name="purple_tint">#88995f86</color>    <color name="orange_tint">#aaffbf00</color>    <color name="magenta_tint">#88ff33cc</color>    <color name="transparent">#0000</color> </resources> 

<?xml version="1.0" encoding="utf-8"?> <resources>    <!-- Orange -->    <style name="OrangeDialogTheme" parent="@android:style/Theme.Dialog">      <item name="android:tint">@color/orange_tint</item>      <item name="android:windowBackground">@color/orange_tint</item>    </style>        <style name="OrangeAlertDialogTheme" parent="OrangeDialogTheme">       <item name="android:windowBackground">@color/transparent</item>    </style>            <!-- Red -->      <style name="RedDialogTheme" parent="@android:style/Theme.Dialog">       <item name="android:tint">@color/red_tint</item>   </style>        <style name="RedAlertDialogTheme" parent="RedDialogTheme">       <item name="android:windowBackground">@color/magenta_tint</item>    </style> </resources>

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. 【Android动态布局】之【使用addView方法时,如何保持已有动态控件
  6. Android中动态设置多继承Style/Theme
  7. Android自动提示--AutoCompleteTextView、MultiAutoCompleteText
  8. Android(安卓)API开发之OpenGL开发之Android(安卓)OpenGL之使用G
  9. android 中使用sqLite例子

随机推荐

  1. Android(安卓)开发手记一NDK编程实例
  2. Android(安卓)创建与解析XML(一)—— 概述
  3. Android(安卓)开发有哪些新技术出现?
  4. 转:如何运行Android(安卓)sdk sample中的
  5. 【小萌伴Android】相关文章目录
  6. 自学android,记录小知识一
  7. Android(安卓)HttpURLConnection应用技巧
  8. Android(安卓)Runtime Permission 详解
  9. 在虚拟机中安装apk软件
  10. Android(安卓)安全框架 -- 总概