gpt4 book ai didi

android - 如何在窗口管理器 View 中获得焦点

转载 作者:行者123 更新时间:2023-11-30 02:32:16 26 4
gpt4 key购买 nike

我使用 WindowManager 创建 View 并将 View 添加到屏幕,但我无法使 View 聚焦。我想我正确设置了 WindowManager.LayoutParams。

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
pushView = LayoutInflater.from(getApplicationContext()).inflate(
R.layout.push, null);

btn = (Button) findViewById(R.id.btn);
cancelBtn = (Button) pushView.findViewById(R.id.cancelBtn);
windowManager = getWindowManager();
handler = new MyHandler();

pushView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
System.out.println("onclick");
windowManager.removeView(pushView);
}
});


btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.y = 0;
params.x = 0;

windowManager.addView(pushView, params);

new Timer().schedule(new TimerTask() {

@Override
public void run() {
Message msg = handler.obtainMessage();
handler.sendEmptyMessage(0x123);
}
}, 5000);

}
});

}

我想让pushView'focusable来处理view的事件,这个问题困扰了我很久,谁能帮帮我...

最佳答案

您只需删除 FLAG_NOT_FOCUSABLE 标志:

params.flags = params.flags & ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

关于android - 如何在窗口管理器 View 中获得焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27166686/

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