PopupWindow的基本使用
生活随笔
收集整理的這篇文章主要介紹了
PopupWindow的基本使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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"/><TextViewandroid: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"/><TextViewandroid: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() {@Overridepublic void onClick(View view) {popupWindow.dismiss();mPresenter.editAlarm();}});clearLayout.setOnClickListener(new View.OnClickListener() {@Overridepublic 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);}?
轉(zhuǎn)載于:https://www.cnblogs.com/i-love-kobe/p/5576923.html
總結(jié)
以上是生活随笔為你收集整理的PopupWindow的基本使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android Studio的下载和安装
- 下一篇: jQuery基础修炼圣典—DOM篇(二)