android彈出對話方塊

2021-08-31 10:44:04 字數 1388 閱讀 9847

目前學習到的android有三種方式彈出對話方塊:

1、alertdialog

alertdialog是非阻塞的,簡單的記錄一下建立的**:

alertdialog.builder builder;  

alertdialog alertdialog;

builder = new alertdialog.builder(mcontext);

builder.settitle("測試選單");

alertdialog = builder.create();

alertdialog.show();

new alertdialog.builder所需要的引數,經過測試和網上查詢,發現是要activity才可以的

所以最後方式了這種方式

2、popupwindow

popupwindow是阻塞的對話方塊,基本上滿足要求,但是最後獲取焦點,

進行onkey事件還是遇到了很多的問題。奇怪,還是把部分**貼出來:

//建立popupwindow

layoutinflater mflayout = getlayoutinflater();

view view = mflayout.inflate(r.layout.popupwindow, null);

popupwindow mpopupwindow = new popupwindow(view,

layoutparams.fill_parent, layoutparams.wrap_content);

//獲得焦點

//不知道為什麼,最後還是不響應onkey事件,用下面的方法可以

view.setfocusableintouchmode(true);//view是建立pop的子view

view.setonkeylistener(new onkeylistener()

});3、採用service上面,通過intent,彈出乙個activity選單

intent activityintent = new intent(mcontext, mainactivity.class);

activityintent.setflags(intent.flag_activity_new_task);

"mcurkeyboard", mcurkeyboard);

bundle mbundle = new bundle();

mbundle.putint("mcurkeyboard", 1);

activityintent.putextras(mbundle);

mcontext.startactivity(activityintent);

只是簡單的乙個思路,具體的細節,在實現的時候可以上網看看例子。

Android 全域性彈出對話方塊

方案一 使用系統彈窗許可權 1.1 先加許可權 1.2 建立alertdialog時候設定型別為 alertdialog.getwindow settype windowmanager.layoutparams.type system alert 缺點 方案二 彈個activity替代 2.1 設定...

彈出對話方塊

先定義 private view view private alertdialog mprotocoldialog 彈出對話方塊 private void loadprotocol mprotocoldialog new alertdialog.builder this settitle getst...

彈出對話方塊

call function popup to confirm exporting titlebar diagnose object text question anything else?text button 1 yes?icon button 1 15 text button 2 no 002 ...