zoukankan      html  css  js  c++  java
  • PopupWindow的基本使用

    1>写好布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="vertical" >
        
        <LinearLayout 
            android:id="@+id/edit_alarm"
            android:layout_width="match_parent"
            android:layout_height="60dp">
            
            <ImageView 
                android:layout_width="24dp"
                android:layout_marginLeft="16dp"
                android:layout_height="match_parent"
                android:src="@drawable/ic_alarm_add"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/edit_alarm"
                style="@style/popupwindow_text_style"/>
             
        </LinearLayout>
        
        <View  
            android:layout_width="220dp"  
            android:layout_height="1dp"
            android:background="?android:attr/listDivider" /> 
        <LinearLayout 
            android:id="@+id/clear_alarm"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            >
            <ImageView 
                android:layout_width="24dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="16dp"
                android:src="@drawable/ic_alarm_off"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/popupwindow_text_style"
                android:text="@string/clear_alarm" />
            
        </LinearLayout>
           
    
    </LinearLayout>

    2>代码:

    public void showAlarmPopupWindow() {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.alarm_popupwindow , null ,false);
            LinearLayout editLayout = (LinearLayout)view.findViewById(R.id.edit_alarm);
            LinearLayout clearLayout = (LinearLayout)view.findViewById(R.id.clear_alarm);
    
            final PopupWindow popupWindow = new PopupWindow(view , ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT , true);
    
            editLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    mPresenter.editAlarm();
                }
            });
            clearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    mPresenter.clearAlarm();
                }
            });
            popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
            popupWindow.showAsDropDown(getActivity().findViewById(R.id.toolbar) , getActivity().getWindowManager().getDefaultDisplay().getWidth() - popupWindow.getWidth() , 1);
        }
  • 相关阅读:
    jQuery诞生记-原理与机制
    你所不知的 CSS ::before 和 ::after 伪元素用法
    http中get与post的区别
    Http请求方法
    TCP/IP详解学习笔记(4)-ICMP协议,ping和Traceroute
    TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议
    TCP/IP详解学习笔记(2)-数据链路层
    TCP/IP详解学习笔记(1)-基本概念
    全面解析Java的垃圾回收机制
    深入Java虚拟机:JVM中的Stack和Heap
  • 原文地址:https://www.cnblogs.com/i-love-kobe/p/5576923.html
Copyright © 2011-2022 走看看