I use the WindowManager to create a view and add the view to the screen,but I cannot get the view focusable.I think I set the WindowManager.LayoutParams correct.
@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);
}
});
}
I want get the pushView'focusable to handle view's event.This problem has troubled me for a long time.Who can help me...