Android中的PopupWindow的使用

 1 PopupWindow 需要一个自定义的布局文件
 2 列如:popupwindow.xml
 3 
 4 <?xml version="1.0" encoding="utf-8"?>
 5 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     android:background="#000"
 9     android:orientation="vertical" >
10     <TextView
11         android:textSize="25dp"
12         android:textColor="#ffffff"
13         android:id="@+id/textView1"
14         android:layout_width="fill_parent"
15         android:layout_height="wrap_content"
16         android:text="@string/start" />
17 
18     <TextView
19         android:textSize="25dp"
20         android:textColor="#ffffff"
21         android:id="@+id/textView2"
22         android:layout_width="fill_parent"
23         android:layout_height="wrap_content"
24         android:text="@string/uninstall" />
25 
26     <TextView
27         android:textSize="25dp"
28         android:textColor="#ffffff"
29         android:id="@+id/textView3"
30         android:layout_width="fill_parent"
31         android:layout_height="wrap_content"
32         android:text="@string/detil" />
33 
34 </LinearLayout>
35 
36 LayoutInflater flater=LayoutInflater.from(context);
37 View popview=flater.inflate(R.layout.popuwindow, null);
38 PopupWindow popup=new PopupWindow(popview, 200, 130,true);
39 第一个参数:是自定义的布局文件
40 第二、三个参数:显示的宽、高
41 第四个参数:是否获得焦点
42 popup.showAsDropDown(view);显示在view(控件)的下面,
43
  //创建一个自适应大小的弹出菜单
44 new PopupWindow(popview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true) 

45 //关闭popuwindow窗口
   popup.dismiss();

47 要想实现弹出的菜单的里面的菜单项的事件功能,就必须使用popview.findViewById(R.id.textview1)这样的方法之后才能为其添加事件监听器

 

转载于:https://www.cnblogs.com/tianshidechibang234/p/3198762.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值