使用样式文件,在values 目录下新建styles.xml文件,编写如下代码:

<resources>    <style name="dialog" parent="@android:style/Theme.Dialog">         <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowIsTranslucent">false</item>        <item name="android:windowNoTitle">true</item>        <item name="android:background">@android:color/black</item>        <item name="android:windowBackground">@null</item>        <item name="android:backgroundDimEnabled">false</item>    </style></resources>


调用时,使用AlerDialog的接口类,Dialog 接口编写如下代码:

Dialog dialog = new Dialog(SetActivity.this, R.style.dialog);                    dialog.setContentView(R.layout.test);                    dialog.show();


下面我们查看一下Dialog的源码文件,里面的构造函数为如下:

public Dialog(Context context, int theme) {        mContext = new ContextThemeWrapper(            context, theme == 0 ? com.android.internal.R.style.Theme_Dialog : theme);        mWindowManager = (WindowManager)context.getSystemService("window");        Window w = PolicyManager.makeNewWindow(mContext);        mWindow = w;        w.setCallback(this);        w.setWindowManager(mWindowManager, null, null);        w.setGravity(Gravity.CENTER);        mUiThread = Thread.currentThread();        mDismissCancelHandler = new DismissCancelHandler(this);    }


这里面我们可以看出,Android 使用了默认的构造函数为Dialog 设置样式,如果没有为其设置样式,即默认加载事先编写好的样式文件,Dialog 一共由多个9.png的图片构成,大部分都是带有边框的9.png图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助


前后效果对比

未设置前:



设置后:



转自:http://terryblog.blog.51cto.com/1764499/388582

更多相关文章

  1. Android(安卓)StatusBar相关设置
  2. Android(安卓)XML Shape使用入门
  3. Source not found-Android(安卓)使用隐藏API(2)
  4. android中的主题(theme)的定义
  5. LBE 安全大师支持android 4.4注入分析
  6. Android分辨率自适应
  7. ionic打包apk时报错No resource identifier found for attribute
  8. android从资源文件中读取文件流显示
  9. NPM 和webpack 的基础使用

随机推荐

  1. android 加载大图的原理和实现
  2. Android(安卓)RecyclerView网格布局
  3. Android左右滑动切换图片
  4. Android实现手势缩放图片
  5. Android上层怎样读写proc节点(示例)
  6. early_param("earlyprintk", setup_early
  7. android下为自己定义wifimanager类
  8. View 绘制机制 -- How Android(安卓)Draw
  9. 一维byte数组旋转
  10. 使用Notification发送消息通知