在activity啟動後立即彈出PopupWindow的三個方法
阿新 • • 發佈:2019-01-26
那我們只需要在activity完全啟動後再彈出PopupWindow就行了。
第一種方法: 利用Activity的 onWindowFocusChanged()方法
- @Override
- publicvoid onWindowFocusChanged(boolean hasFocus) {
- // TODO Auto-generated method stub
- super.onWindowFocusChanged(hasFocus);
- // 彈出PopupWindow的具體程式碼
- }
第二種方法: 利用Handler和Runnable
-
private Handler mHandler =
- @Override
- protectedvoid onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- mHandler.postDelayed(mRunnable, 500);
- }
- private Runnable mRunnable = new Runnable() {
-
public
- // 彈出PopupWindow的具體程式碼
- }
- };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler.sendEmptyMessageDelayed(SHOWWINDOW, 200);
}
private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case SHOWWINDOW: popTipMessage(); break; case ClOSEWINDOW: break; } } };