手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android弹出窗口实现方法
Android弹出窗口实现方法
摘要:本文实例讲述了Android弹出窗口实现方法。分享给大家供大家参考,具体如下:直接上代码:/***弹窗--新手指引*@paramcxt*@p...

本文实例讲述了Android弹出窗口实现方法。分享给大家供大家参考,具体如下:

直接上代码:

/** * 弹窗--新手指引 * @param cxt * @param id 资源编号 * @create_time 2011-7-27 下午05:12:49 */ public static void displayWindow(Context cxt, int id) { final TextView imgTV = new TextView(cxt.getApplicationContext()); imgTV.setBackgroundDrawable(cxt.getResources().getDrawable(id));//设置背景 final WindowManager wm = (WindowManager) cxt.getApplicationContext().getSystemService("window"); WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams(); wmParams.type = 2002; wmParams.format = 1; wmParams.flags = 40; wmParams.width = LayoutParams.FILL_PARENT; wmParams.height = LayoutParams.FILL_PARENT; wm.addView(imgTV, wmParams); imgTV.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { wm.removeView(imgTV);//点击,将该窗口消失掉 } }); }

别忘了在AndroidManifest.xml中添加权限:

复制代码 代码如下:<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

android.permission.SYSTEM_ALERT_WINDOW

允许一个程序打开窗口使用 TYPE_SYSTEM_ALERT,显示在其他所有程序的顶层(Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. )

这个FIRST_SYSTEM_WINDOW的值就是2000。2003和2002的区别就在于2003类型的View比2002类型的还要top,能显示在系统下拉状态栏之上!

希望本文所述对大家Android程序设计有所帮助。

【Android弹出窗口实现方法】相关文章:

基于Android中手势交互的实现方法

Android上网获取网络上的图片方法

android图库竖屏不显示status bar的解决方法

Android开发笔记之:Splash的实现详解

Android中获得手机屏幕大小实现代码

Android开发之电源管理

Android仿QQ空间主页面的实现

Android RadioButton单选框的使用方法

Android中手机号码归属地查询实现

Android中使用sax解析xml文件的方法

精品推荐
分类导航