{"id":536,"date":"2023-07-24T14:52:58","date_gmt":"2023-07-24T06:52:58","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=536"},"modified":"2023-07-24T14:52:58","modified_gmt":"2023-07-24T06:52:58","slug":"app%e5%bc%80%e5%8f%91popup%e5%bc%b9%e5%87%ba%e5%b1%82%e6%9c%89%e4%bb%80%e4%b9%88%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/536\/","title":{"rendered":"app\u5f00\u53d1popup\u5f39\u51fa\u5c42\u6709\u4ec0\u4e48\u6ce8\u610f\u4e8b\u9879\uff1f"},"content":{"rendered":"
\u6807\u9898\uff1aApp\u5f00\u53d1\u4e4bPopup\u5f39\u51fa\u5c42\u8be6\u89e3<\/p>\n
\u5f15\u8a00\uff1a<\/p>\n
\u5728App\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u5f88\u591a\u65f6\u5019\u9700\u8981\u4f7f\u7528Popup\u5f39\u51fa\u5c42\uff0c\u5982\u6d88\u606f\u63d0\u793a\u3001\u786e\u8ba4\u6846\u3001\u9009\u62e9\u6846\u7b49\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u8be6\u7ec6\u4ecb\u7ecdPopup\u5f39\u51fa\u5c42\u7684\u539f\u7406\u53ca\u5176\u8be6\u7ec6\u5b9e\u73b0\u8fc7\u7a0b\uff0c\u5e2e\u52a9\u5165\u95e8\u4eba\u5458\u638c\u63e1Popup\u5f39\u51fa\u5c42\u5728App\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u3002<\/p>\n
\u4e00\u3001Popup\u5f39\u51fa\u5c42\u7684\u539f\u7406<\/p>\n
Popup\u5f39\u51fa\u5c42\u5728App\u5f00\u53d1\u4e2d\u5360\u6709\u91cd\u8981\u7684\u5730\u4f4d\uff0c\u4e3b\u8981\u5e94\u7528\u4e8e\u4e34\u65f6\u5c55\u793a\u4e00\u4e9b\u4fe1\u606f\u6216\u8005\u9700\u8981\u7528\u6237\u64cd\u4f5c\u7684\u754c\u9762\u3002\u5176\u539f\u7406\u662f\u5728\u539f\u754c\u9762\u4e4b\u4e0a\u8986\u76d6\u4e00\u5c42\u534a\u900f\u660e\u906e\u7f69\uff0c\u5f39\u51fa\u5c42\u4e0a\u65b9\u5c55\u793a\u6240\u9700\u5185\u5bb9\u3002\u7528\u6237\u53ef\u4ee5\u5728\u5f39\u51fa\u5c42\u8fdb\u884c\u64cd\u4f5c\uff0c\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u8be5\u5f39\u51fa\u5c42\u4f1a\u6d88\u5931\uff0c\u6062\u590d\u5230\u539f\u754c\u9762\u3002<\/p>\n
\u4e8c\u3001Popup\u5f39\u51fa\u5c42\u7684\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n
\u5177\u4f53\u5b9e\u73b0Popup\u5f39\u51fa\u5c42\u9996\u5148\u8981\u521b\u5efa\u4e00\u4e2a\u5f39\u51fa\u5c42\u7684\u5e03\u5c40\uff0c\u7136\u540e\u5c06\u5c55\u793a\u5185\u5bb9\u653e\u5165\u8fd9\u4e2a\u5e03\u5c40\u4e2d\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u521b\u5efaPopup\u5f39\u51fa\u5c42\uff0c\u4ee5\u53ca\u5982\u4f55\u8bbe\u7f6e\u906e\u7f69\u5c42\u3002<\/p>\n
1. \u521b\u5efaPopup\u5f39\u51fa\u5c42\u7684\u5e03\u5c40<\/p>\n
\u9996\u5148\u8981\u5728App\u7684\u5e03\u5c40\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5e03\u5c40\u3002\u5e03\u5c40\u6587\u4ef6\u53ef\u4ee5\u5305\u542b\u5404\u79cdUI\u5143\u7d20\uff0c\u8fd9\u91cc\u6211\u4eec\u4ee5TextView\u4e3a\u4f8b\uff1a<\/p>\n
“`<\/p>\n<\/p>\n
android:layout_width=”match_parent”<\/p>\n
android:layout_height=”match_parent”><\/p>\n<\/p>\n
android:id=”@+id\/popup_text”<\/p>\n
android:layout_width=”wrap_content”<\/p>\n
android:layout_height=”wrap_content”<\/p>\n
android:text=”\u8fd9\u662f\u4e00\u4e2aPopup\u5f39\u51fa\u5c42” \/><\/p>\n
“`<\/p>\n
2. \u521b\u5efaPopup\u5f39\u51fa\u5c42\u5bf9\u8c61<\/p>\n
\u5728\u4ee3\u7801\u4e2d\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2aPopupWindow\u7c7b\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528setLayoutInflater\u65b9\u6cd5\u5c06\u521b\u5efa\u7684\u5e03\u5c40\u6587\u4ef6\u8f6c\u5316\u4e3aView\u5bf9\u8c61\uff0c\u5e76\u4f20\u9012\u7ed9PopupWindow\u3002<\/p>\n
“`<\/p>\n
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);<\/p>\n
View popupView = layoutInflater.inflate(R.layout.popup_layout, null);<\/p>\n