码迷,mamicode.com
首页 > Windows程序 > 详细

PopupWindow的基本使用

时间:2016-06-12 12:08:31      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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);
    }

 

PopupWindow的基本使用

标签:

原文地址:http://www.cnblogs.com/i-love-kobe/p/5576923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!