使用样式文件,在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>
<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.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);
}
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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助
前后效果对比
未设置前:
设置后:
相关推荐
Android自定义属性实现带边框效果的TextView,详细使用请查看:http://blog.csdn.net/llew2011
项目中多处用到对话框,本篇文章主要介绍了Android实现圆角对话框Dialog的示例代码,有兴趣的可以了解一下。
RCImageView 自定义圆角ImageView,带边框效果
很想做个天气预警的功能, 想用preferences来做界面。 看了很多preferences感觉定制性太差 所以自己做了一个。 应该是不错的demo 定制preferences在preferencesActivity中的布局 和自定义了对话框的布局
介绍了Android 去掉自定义dialog的白色边框,有需要的朋友可以参考一下
自定义TextView带边框,可以动态更边框颜色以及字体颜色,可设置边框圆角
Android Studio 实现对话框圆角,毛玻璃模糊效果
安卓Android源码——dialog去除边框代码.zip
一个简单的自定义AlertDialog
Android自定义Gallery 自定义边框 底部小圆点 自动切换
Android自定义身份证相机-IDCardCamera 效果图: 功能特点 自定义相机界面 支持开启闪光灯 支持手动触摸屏幕对焦 支持自动对焦 支持图片自动裁剪 支持图片手动不规则裁剪 2 使用 Step 1. 添加JitPack仓库 在...
Android应用源码之dialog去除边框代码_dialog
Android自定义圆形图片,可设置最多两个的外边框。包括从网络获取图片显示。 解决图片锯齿问题。 解决图片变形问题。 文章地址:http://blog.csdn.net/alan_biao/article/details/17379925
Android 自定义阴影,自定义颜色边框阴影,轻量实现demo
自定义带标题边框的Layout,像Java-swing的JPanel效果,本例继承LinearLayout,继承其他Layout是一样的过程。
Android自定义Iphone风格的圆角边框开关按钮,用xml实现,无图片资源
本文实例讲述了Android开发实现去除bitmap无用白色边框的方法。分享给大家供大家参考,具体如下: 图示 如下图所示,之前介绍过Android Bitmap的用法,这里提供的工具类作用是,去除内容区域以外的白色边框。 代码 ...
android创建一个自定义与多边形边框的ImageView.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。