0
如何在呼叫屏幕上添加彈出對話框?我將使用BroadcastReceiver
來收聽來電並顯示它。我需要一個關於如何編寫允許通過來電進行對話的活動的想法。另外,如何讓對話框移動到屏幕的任何部分?我已經有BroadcastRceiver
實施和執行其他功能,所以我可以只使用一個意向,並開始從這個BroadcastRceiver
在呼叫屏幕上添加彈出對話框
如何在呼叫屏幕上添加彈出對話框?我將使用BroadcastReceiver
來收聽來電並顯示它。我需要一個關於如何編寫允許通過來電進行對話的活動的想法。另外,如何讓對話框移動到屏幕的任何部分?我已經有BroadcastRceiver
實施和執行其他功能,所以我可以只使用一個意向,並開始從這個BroadcastRceiver
在呼叫屏幕上添加彈出對話框
活動開始一個活動,然後使用AlertDialog生成器從該活動以提示對話框
組自定義查看自定義對話框appearence
試試這個
AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = inflater.inflate(R.layout.caller_dialog, null);
ImageView button = dialogView.findViewById(R.id.close_btn);
builder.setView(dialogView);
final AlertDialog alert = builder.create();
alert.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
alert.setCanceledOnTouchOutside(true);
alert.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alert.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setGravity(Gravity.TOP);
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//close the service and remove the from from the window
alert.dismiss();
}
});
如何讓我在電話屏幕上的對話框活動?我也想通過將它拖出屏幕取消它。 – Slay 2014-12-07 11:22:12
你可以參考這個線程關於創建模態覆蓋 http://stackoverflow.com/questions/4481226/creating-a-system-overlay-window-always-on-top – 2014-12-07 11:31:00
謝謝,幫助。但是,如何使其可浮動,以便將其拖動到屏幕上的任何位置? – Slay 2014-12-07 11:43:04