zoukankan      html  css  js  c++  java
  • 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)这样的方法之后才能为其添加事件监听器
  • 相关阅读:
    四川第七届 C Censor (字符串哈希)
    四川第七届 C Censor (字符串哈希)
    Android:实现两个Activity相互切换而都不走onCreate()
    正宗佛祖凝视-原装正版
    iOS中数组遍历的方法及比較
    html5 返回当前地理位置的坐标点(经纬度)
    Android之——卸载应用程序
    Android—— 4.2 Vold挂载管理_NetlinkManager (四)
    2014年java软件project师面试题收集
    C++刷题——2736: 指针练习--输出最大值
  • 原文地址:https://www.cnblogs.com/tianshidechibang234/p/3198762.html
Copyright © 2011-2022 走看看