Android中PopupWindow的使用
来源:互联网 发布:淘宝双方已评 不显示 编辑:程序博客网 时间:2024/05/17 06:07
- public class PopUpActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- LayoutInflater inflater = LayoutInflater.from(this);
- // 引入窗口配置文件
- View view = inflater.inflate(R.layout.main2, null);
- // 创建PopupWindow对象
- final PopupWindow pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);
- Button btn = (Button) findViewById(R.id.btn);
- // 需要设置一下此参数,点击外边可消失
- pop.setBackgroundDrawable(new BitmapDrawable());
- //设置点击窗口外边窗口消失
- pop.setOutsideTouchable(true);
- // 设置此参数获得焦点,否则无法点击
- pop.setFocusable(true);
- btn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if(pop.isShowing()) {
- // 隐藏窗口,如果设置了点击窗口外小时即不需要此方式隐藏
- pop.dismiss();
- } else {
- // 显示窗口
- pop.showAsDropDown(v);
- }
- }
- });
- }
- }
main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <Button
- android:id="@+id/btn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="dianji" />
- </LinearLayout>
main2.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <Button
- android:id="@+id/a"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="AAAAA" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="BBBBB" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="CCCCC" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="DDDDD" />
- </LinearLayout>
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android中PopupWindow的使用
- Android 中PopupWindow使用
- android中PopupWindow的使用详解
- Android中关于PopupWindow的使用简介
- Android中PopupWindow的基本使用
- Android中PopupWindow的基本使用
- 关于android中PopupWindow的基本使用
- 解析Thu Aug 08 09:16:52 CST 2013格式的字符串为日期对象
- PowerDesigner的使用安装和数据库创建
- 英文缩写及简介,不断更新中
- VC6下CreateThread的回调函数无法直接用函数模板生成,需要一层分装
- 学生信息管理系统验收总结
- Android中PopupWindow的使用
- shell命令之解压缩
- 针对于jetty部署iMatrix平台内存溢出问题解决方案
- 搜索引擎大PK谁将是最后的王者
- Node.js Cannot find module 'xxx' 有关问题解决
- FreeBSD软件安装卸载工具--Ports和Packages详解!
- 启动apk或者服务的常用方法
- MFC实现文本的基本操作
- css设置浏览器的滚动条样式