Android popupWindow彈出窗體實(shí)現(xiàn)方法分析
本文實(shí)例講述了Android popupWindow彈出窗體實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
1. 建立popupwindow顯示的布局頁面(普通的view任意布局)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="80dip" android:background="@drawable/popup_yellow_window_bg" android:orientation="horizontal" > <TextView android:id="@+id/popupwindow_app_uninstall_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:drawableTop="@drawable/kn_malware_scan_deep_click" android:text="卸 載"/> </LinearLayout>
2. activity中布局加載以及填充,建立popupwindow對象,設(shè)置相應(yīng)參數(shù)或?qū)傩?/p>
View contentView = View.inflate(getApplicationContext(), R.layout.popup_window, null); LinearLayout ll_uninstall = (LinearLayout) contentView.findViewById(R.id.ll_uninstall); //設(shè)置popupwindow內(nèi)布局組件的監(jiān)聽(與其他組件相似) MyOnClickListener l = new MyOnClickListener(position); ll_uninstall.setOnClickListener(l); PopupWindow mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, 70); int[] arrayOfInt = new int[2]; view.getLocationInWindow(arrayOfInt); int x = arrayOfInt[0] + 60; int y = arrayOfInt[1]; //1 指定popupwindow的背景 2 popupwindow能夠獲得焦點(diǎn) mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setFocusable(true); mPopupWindow.showAtLocation(view, Gravity.LEFT|Gravity.TOP, x, y); //在合適位置取消popupwindow顯示 mPopupWindow.dismiss();
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android窗口相關(guān)操作技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章

Android Studio打包.so庫到apk中實(shí)例詳解

Android Studio 修改類的默認(rèn)注釋圖文教程

android listview進(jìn)階實(shí)例分享

深入解析Android App的LayoutInflate布局

Android自定義狀態(tài)欄顏色與應(yīng)用標(biāo)題欄顏色一致

Android啟動頁用戶相關(guān)政策彈框的實(shí)現(xiàn)代碼

Android 6.0區(qū)別U盤和SD卡設(shè)備的方法詳解

Android PopupMenu彈出菜單的實(shí)現(xiàn)