gpt4 book ai didi

android - 如何使覆盖窗口可触摸

转载 作者:行者123 更新时间:2023-11-30 00:10:08 25 4
gpt4 key购买 nike

我正在我的应用程序中创建一个功能,在屏幕上显示一个带有文本的覆盖窗口,当它出现时,我尝试触摸那个窗口,它实际上触摸了那个窗口后面我需要使该窗口可触摸,我应该使用哪些参数?这是我的代码

        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater screenNotificationInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
layOverTopviewNotification = screenNotificationInflater.inflate(R.layout.layout_notification, null);
TextView layOverText = (TextView) layOverTopviewNotification.findViewById(R.id.notification_layout);
layOverText.setText(athkarString[completed]);

params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.x = 0;
params.y = 0;
params.gravity = Gravity.TOP;
windowManager.addView(layOverTopviewNotification, params);

最佳答案

我终于找到了答案。

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

inflater = LayoutInflater.from(PlayAthkarService.this);

textView = new TextView(PlayAthkarService.this);
textView.setBackgroundResource(R.drawable.floating_window);
textView.setTextSize(20);
textView.setText(athkarString[completed]);
textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.OPAQUE);
}else {
params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
, WindowManager.LayoutParams.TYPE_PRIORITY_PHONE,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.OPAQUE);
}

params.gravity = Gravity.TOP | Gravity.RIGHT ;
params.x = 0;
params.y = 50;

windowManager.addView(textView, params);

关于android - 如何使覆盖窗口可触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48288965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com