使用样式文件,在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 接口编写如下代码:

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

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

public Dialog(Contextcontext, int theme){
mContext
= new ContextThemeWrapper(
context,theme
== 0 ? com.android. internal .R.style.Theme_Dialog:theme);
mWindowManager
= (WindowManager)context.getSystemService( " window " );
Windoww
= 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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助

前后效果对比

未设置前:

  Android 对话框【Dialog】去除白色边框代码 - doyee - About Doyee

设置后:

  Android 对话框【Dialog】去除白色边框代码 - doyee - About Doyee

我的话费充值店-各种面额

电信100元仅售98.60
联通100仅售99.00
移动100仅售99.30

更多相关文章

  1. 布局与样式
  2. 大话企业级Android应用开发实战 文件下载
  3. mipmap和drawable文件夹的区别
  4. Android: /cache中的文件是怎么消失的
  5. Android APK文件结构 完整打包编译的流程 APK安装过程 详解
  6. Android 统一View样式,textview样式
  7. Android读取xxx.properties配置文件中文出现乱码解决方法
  8. Android Studio(九):引用jar及so文件

随机推荐

  1. android 4.2.1 下载和编译
  2. android 测试 monkeyrunner
  3. Android的onActivityResult不被调用的解
  4. init.rc 学习
  5. Android: density,dp,sp,px
  6. Android(安卓)8.0启动Service问题
  7. 加快Android(安卓)Stduio编译速度方法之
  8. Android系统详解之获取图片和视频的缩略
  9. 加速Android(安卓)Studio---Gradle构建
  10. could not find adb.exe