0

我想将焦点从视图移动WindowManager到其他视图以退出应用程序。但我不想使用FLAG_NOT_FOCUSABLE. 有没有其他方法可以解决这个问题?

例如,

public class WindowManagerTest extends Activity 
{      
    public void onCreate(Bundle savedInstanceState) 
    {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.windowmanagertest);

         WindowManager wm = (WindowManager)getSystemService(
            Context.WINDOW_SERVICE);
         Display dis = wm.getDefaultDisplay();
         TextView result = (TextView)findViewById(R.id.result);
         Point pt = new Point();
         dis.getSize(pt);
         result.setText("width = " + pt.x + "\nheight = " + pt.y +
            "\nrotate = " + dis.getRotation());

         ImageView img = new ImageView(this);
         img.setImageResource(R.drawable.clover);
         WindowManager.LayoutParams param = new WindowManager.LayoutParams();
         param.gravity=Gravity.LEFT | Gravity.TOP;
         param.x = 100;
         param.y = 20;
         param.width = WindowManager.LayoutParams.WRAP_CONTENT;
         param.height = WindowManager.LayoutParams.WRAP_CONTENT;
         //param.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
         param.format = PixelFormat.TRANSLUCENT;

         wm.addView(img, param);
   }
}
4

1 回答 1

1

听起来您正在寻找以下内容:

img.setFocusable(true);
img.setFocusableInTouchMode(true);

或在窗口管理器上将它们设置为 false ?

于 2013-09-30T17:04:35.727 回答