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