So I am making a sticky note sorta thing that always appears on top and user can press on it to type on it. So here is my working code:

 mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); 
 LayoutInflater layoutInflater = 
 (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 myView = layoutInflater.inflate(R.layout.notepad, null ); //notepad.xml contains the EditText

  WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
        PixelFormat.TRANSLUCENT);
  mWindowManager.addView(myView, params);

The problem is that when I use the flag TYPE_SYSTEM_OVERLAY, I can't get focus to type on the EditText. Alternate would be to use TYPE_SYSTEM_ALERT and I can use the EditText to type on, but then the entire background would freeze. How can I allow the user to type without interrupting background activity (aka game, video, scrolling thru Facebook etc)

有帮助吗?

解决方案

There is an opensource library for that. Its called the standOut library. Have a look.

enter image description here

It may help you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top