设置Dialog全屏显示
2016-01-27 14:26
369 查看
默认的Dialog是不能全屏的。也就是怎么设置Dialog的Layout和通过
Window window = mDialog.getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = (int) (screenUtils.getWidth());
layoutParams.height = (int) (screenUtils.getHeight());
都没用的。
给出实现Dialog实现全屏的两种方式:
1、代码实现。这中方法相对比较简单
首先继承Dialig,然后再构造函数中添加
super(context, android.R.style.Theme);
setOwnerActivity((Activity)context);
这里面显示Dialog是将状态栏也隐藏掉了,如果不想隐藏就指定长宽,可以采用设置layoutParams.长宽属性,然后通过
WindowManager.LayoutParams layoutParams = window.getAttributes();
这里面的layoutParams 去作为新的参数传给windows
即:window.setAttributes(layoutParams);
2、XML实现
首先,在values文件中添加一个XML文件,
其次,在XML文件中设置一个style
然后,添加如下代码:
<style name="Dialog_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
最后,在代码里设置Dialog的Theme
Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen);
dialog.setContentView(R.layout.main);
dialog.show();
里面的ScreenUtils我也贴出来
【欢迎上码】
【微信公众号搜索 h2o2s2】
Window window = mDialog.getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = (int) (screenUtils.getWidth());
layoutParams.height = (int) (screenUtils.getHeight());
都没用的。
给出实现Dialog实现全屏的两种方式:
1、代码实现。这中方法相对比较简单
首先继承Dialig,然后再构造函数中添加
super(context, android.R.style.Theme);
setOwnerActivity((Activity)context);
这里面显示Dialog是将状态栏也隐藏掉了,如果不想隐藏就指定长宽,可以采用设置layoutParams.长宽属性,然后通过
WindowManager.LayoutParams layoutParams = window.getAttributes();
这里面的layoutParams 去作为新的参数传给windows
即:window.setAttributes(layoutParams);
2、XML实现
首先,在values文件中添加一个XML文件,
其次,在XML文件中设置一个style
然后,添加如下代码:
<style name="Dialog_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
最后,在代码里设置Dialog的Theme
Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen);
dialog.setContentView(R.layout.main);
dialog.show();
里面的ScreenUtils我也贴出来
import android.content.Context; import android.util.DisplayMetrics; import android.view.WindowManager; /** * 获取屏幕的分辨率帮助类 * @param context * @return width or height * @see ScreenUtils * */ public class ScreenUtils { private int width, height; private Context context; public ScreenUtils(Context context) { this.context = context; init(); } private void init() { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); width = outMetrics.widthPixels; height = outMetrics.heightPixels; } public int getWidth() { return width; } public int getHeight() { return height; } }
【欢迎上码】
【微信公众号搜索 h2o2s2】
相关文章推荐
- android dialog关闭按钮 在半透明区域(最简单实现)
- 设置Dialog全屏,背景使用Dialog布局颜色
- [安卓开发] 完美解决Dialog不能全屏
- android 超简单实现dialog全屏显示
- HTML5:标记文字
- Jboss中使用Log4J输出Hibernate所生成的SQL中的参数值
- django 的orm的一些操作
- 解决:Internet Explorer无法打开该Internet站点.请求的站点不可用,或找不到.请以后再试.
- js+css绘制颜色动态变化的圈中圈效果
- 如何配置EJB3消息处理并发数[Message Driven Bean]
- SVN服务器搭建和使用(一)
- linux环境coding,并远程同步到windows
- IBM AppScan
- 一篇还不错的介绍头文件的小文章
- Pascal's Triangle 2(leetcode java)
- Java项目经验——软件工程师成长的关键
- java组合算法应用:购物满减(任意数字组合相加在某个范围内)
- 1002. A+B for Polynomials (25)
- ASP.NET MVC FileResult的本质
- druid数据源例子