Android popupWindow彈出窗體實現(xiàn)方法分析
本文實例講述了Android popupWindow彈出窗體實現(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ù)或屬性
View contentView = View.inflate(getApplicationContext(), R.layout.popup_window, null); LinearLayout ll_uninstall = (LinearLayout) contentView.findViewById(R.id.ll_uninstall); //設置popupwindow內布局組件的監(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能夠獲得焦點 mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setFocusable(true); mPopupWindow.showAtLocation(view, Gravity.LEFT|Gravity.TOP, x, y); //在合適位置取消popupwindow顯示 mPopupWindow.dismiss();
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android窗口相關操作技巧總結》、《Android開發(fā)入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
深入解析Android App的LayoutInflate布局
這篇文章主要介紹了Android App的LayoutInflate布局,對LayoutInflate編寫中經(jīng)常被無解及產(chǎn)生錯誤的地方進行了深入說明,需要的朋友可以參考下2016-04-04
Android自定義狀態(tài)欄顏色與應用標題欄顏色一致
看IOS上的應用,應用中狀態(tài)欄的顏色總能與應用標題欄顏色保持一致,用戶體驗很不錯,對于這種效果怎么實現(xiàn)的呢?下面小編給大家分享android自定義狀態(tài)欄顏色與應用標題欄顏色一致的實現(xiàn)方法,一起看看吧2016-09-09
Android 6.0區(qū)別U盤和SD卡設備的方法詳解
今天小編就為大家分享一篇Android 6.0區(qū)別U盤和SD卡設備的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Android PopupMenu彈出菜單的實現(xiàn)
這篇文章主要介紹了 Android PopupMenu彈出菜單的實現(xiàn)的相關資料,希望通過本文能幫助到大家,實現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10

