在windowManager中,只有最后添加的View可以单击或执行其他运算符

时间:2015-06-17 07:02:05

标签: android android-windowmanager

我的代码:

    public void setAboveButton() {
        aboveButton = new TextView(mContext);
        ColorDrawable cd = new ColorDrawable(Color.GRAY);
        aboveButton.setBackground(cd);
        aboveButton.setText("<回游戏");
        aboveButton.setGravity(Gravity.CENTER);
        aboveButton.setTextSize(25);
        aboveButton.setClickable(isClickable());
        aboveButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                instance.setVisibility(View.INVISIBLE);
                aboveView.setVisibility(View.INVISIBLE);
                buttomView.setVisibility(View.INVISIBLE);
                aboveButton.setVisibility(View.INVISIBLE);
                buttomButton.setVisibility(View.INVISIBLE);
            }

        });
        android.view.WindowManager.LayoutParams viewParams = new android.view.WindowManager.LayoutParams();
        viewParams.x = -(dm.widthPixels);
        viewParams.y = -(dm.heightPixels);
        viewParams.width = dm.widthPixels / 4;
        viewParams.height = 120;
        instance.mWindowManager.addView(aboveButton, viewParams);
    }
public void setBottomButton() {
        buttomButton = new TextView(mContext);
        ColorDrawable cd = new ColorDrawable(Color.GRAY);
        buttomButton.setBackground(cd);
        buttomButton.setText("发送");
        buttomButton.setGravity(Gravity.CENTER);
        buttomButton.setTextSize(25);
        buttomButton.setClickable(isClickable());
        buttomButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                aboveButton.setVisibility(View.INVISIBLE);
            }

        });
        android.view.WindowManager.LayoutParams viewParams = new android.view.WindowManager.LayoutParams();
        viewParams.x = -(dm.widthPixels);
        viewParams.y = dm.heightPixels;
        viewParams.width = dm.widthPixels / 4;
        viewParams.height = 120;
        instance.mWindowManager.addView(buttomButton, viewParams);
    }    

和我的MainActivity:

public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //Remove title bar
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);
            //Remove notification bar
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.activity_main);
            NoticeBoard.init(MainActivity.this);
            NoticeBoard.getInstance().setAboveView();
            NoticeBoard.getInstance().setBottomView();
            NoticeBoard.getInstance().setBottomButton();
            NoticeBoard.getInstance().setAboveButton();
            setContentView(NoticeBoard.getInstance());
        }

    }

现在,只有最后一个onClick集合有效。我怎样才能让它们一起工作? 如果我在mainActivity中将NoticeBoard.getInstance()。setAboveButton()更改为bottom,那么如果我将NoticeBoard.getInstance()。setButtomButton()更改为mainActivity中的bottom,则bottomButton的onclick将起作用。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。添加flag'WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE'到每个视图中的WindowManager.LayoutParams,然后所有视图都会工作〜