In windowManager only the last added View can click or do other operators

582 views Asked by At

My code:

    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);
    }    

and my 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());
        }

    }

Right now, only the last onClick set works. How can I make them work together? if I change the NoticeBoard.getInstance().setAboveButton() to bottom in the mainActivity,aboveButton's onclick will work,if I change the NoticeBoard.getInstance().setButtomButton() to bottom in mainActivity,bottomButton's onclick will work. Thanks for your help!

1

There are 1 answers

0
Jhon Smith On BEST ANSWER

I solve my problem. add flag'WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE' to WindowManager.LayoutParams in every view,and then all view will be worked~