android popup設定為不可點擊後,按keyback也沒有反應了?

來源:互聯網
上載者:User

標籤:android   android平台   android開發   android studio   

最近自己在做一個項目是需要彈出資訊框, 我使用的是popupwindow,我之前設定的有這個:

m_pop_GameMatchWaitTip.setBackgroundDrawable(new PaintDrawable());
m_pop_GameMatchWaitTip.setOutsideTouchable(true);

就是支援框體外點擊擷取焦點關閉,但是使用者使用效果不佳,現在要改為資訊氣球不可以點擊螢幕關閉,要按keyback鍵關閉,經過自己的一番研究,如下方法可以實現解決這個問題:

就是在這個popupwindow.xml設定檔裡面加上一個無關的view或者沒有點擊的需要的view即可,我設定如下:

 this.m_txt_Match_Name.setFocusableInTouchMode(true);
    this.m_txt_Match_Name.setOnKeyListener(new OnKeyListener() {

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK)
      {
           if (m_pop_GameMatchWaitTip != null)
           {
            m_pop_GameMatchWaitTip.dismiss();
            }
           return true;
        }
       
return false;
}
});

這樣就可以通過監聽這個view,從而關閉這個popupwindow。

希望自己可以協助到其他需要這個問題的朋友,有問題可以大家一起交流。

android popup設定為不可點擊後,按keyback也沒有反應了?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.