笔记82--activity启动后弹出PopupWindow的三个方法

PopupWindow和Dialog区别:http://blog.csdn.net/mwj_88/article/details/30328271

PopupWindow实现类似AlertDialog的半透明效果:http://blog.csdn.net/mwj_88/article/details/39381107

只能在activity完全启动后再弹出PopupWindow。

1、利用Activity的onWindowFocusChanged(),在此方法中弹出

2、利用Handler和Runnable(本质是启动一个延迟的线程)

private Handler mHandler = new Handler();  
  
@Override  
protected void 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 void run() {  
    // 弹出PopupWindow的具体代码  
    }  
};
3、利用Handler(本质是延迟发送一个消息)

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;    
            }    
        }    
    };  



已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页