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);
        }
  • 相关阅读:
    C#知识点总结系列:5、CLR的组成和运转
    SQL知识整理三:变量、全局变量、视图、事务、异常
    SQL知识整理二:锁、游标、索引
    SQL知识整理一:触发器、存储过程、表变量、临时表
    TFS二次开发系列:六、TFS的版本控制
    TFS二次开发系列:五、工作项查询
    TFS二次开发系列:四、TFS二次开发WorkItem添加和修改、保存
    TFS二次开发系列:三、TFS二次开发的第一个实例
    TFS二次开发系列:二、TFS的安装
    TFS二次开发系列:一、TFS体系结构和概念
  • 原文地址:https://www.cnblogs.com/i-love-kobe/p/5576923.html
Copyright © 2011-2022 走看看