使用样式文件,在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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助

前后效果对比

未设置前:

设置后:

更多相关文章

  1. Android(安卓)闪屏页 全屏设置方法
  2. Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画
  3. Eclipse调试Android出现Debug certificate expired问题的解决
  4. android:configChanges属性总结
  5. Android(安卓)SDK无法更新问题解决
  6. Android开发EditText属性
  7. Android(安卓)代码混淆 防止反编译
  8. Android(安卓)SAX解析xml文件
  9. NPM 和webpack 的基础使用

随机推荐

  1. Ubuntu下的adb配置方式
  2. Android(安卓)Google Map API V2(显示地
  3. Android:Activity(四):Activity生命周期
  4. Android手机开发:网络连接-打开Url下载信
  5. AIDL用法总结
  6. Android(安卓)APT(Java注解应用)
  7. Android(安卓)-- NotificationManager an
  8. Android自定义照相机实现 拍照 录像
  9. 安卓控件之单选按钮 (RadioButton和Radio
  10. Android之TabLayout使用和默认选中+移动(