WindowManager专注于拯救我的生命

时间:2013-09-27 18:39:26

标签: android android-windowmanager

我希望将焦点从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);
   }
}

1 个答案:

答案 0 :(得分:0)

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

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

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