android dialog边框去除白色边框实现思路及代码
更新时间:2013年01月13日 17:04:05 作者:
android dialog边框含有白色真是美中不足啊,本文将介绍如何去除白色边框,有思路及代码,感兴趣的朋友可以了解下
使用样式文件,在values 目录下新建styles.xml文件,编写如下代码:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><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的源码文件,里面的构造函数为如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助
前后效果对比
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><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的源码文件,里面的构造函数为如下:
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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图片,所以就是为什么我们上边的样式文件要将其背景去除掉。这个东西搞了我好久,希望对你有帮助
前后效果对比
未设置前:

设置后:

相关文章
Android画图之抗锯齿paint和Canvas两种方式实例
本篇文章主要介绍了Android画图之抗锯齿paint和Canvas两种方式实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-04-04
Android中隐藏状态栏和标题栏的方法汇总(隐藏状态栏、标题栏的五种方法)
这篇文章主要介绍了Android中隐藏状态栏和标题栏的方法汇总(隐藏状态栏、标题栏的五种方法),非常不错,具有参考借鉴价值,需要的朋友可以参考下2017-02-02
android开发通过Scroller实现过渡滑动效果操作示例
这篇文章主要介绍了android开发通过Scroller实现过渡滑动效果,结合实例形式分析了Android Scroller类实现过渡滑动效果的基本原理与实现技巧,需要的朋友可以参考下2020-01-01


最新评论