0

I created it in DialpadFragment, but when the MO call was making, the InCallScreen would always overlay my button. Here is my code:

private void createStopButton() {
    if (mstopButton == null) {
        mstopButton = new Button(mActivity);
        mstopButton.setText("Stop Dial");
    }


    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY|
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
            PixelFormat.OPAQUE);
     params.gravity = Gravity.CENTER | Gravity.TOP;


    final WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);

    mstopButton.setOnClickListener( new View.OnClickListener() {
        public void onClick(View view) {
            mIsRedialStatus = false;
            wm.removeView(mstopButton);
        }
    });

    wm.addView(mstopButton, params);
}

Anybody can help fix how to bring my button up the top of the screen. I have investigated lots of code in internet, I found that they put the top layer related code in a service. Should I also implement it with a service? Thanks very much!

alexunder
  • 2,793
  • 3
  • 15
  • 18

1 Answers1

0

I just answered one similar to this. Check out the the first part of this answer: Creating bodyless activity

But yes, you'll need to do this via a service. Just remember you'll need to find a way to start the service (easiest way is to use an activity).

Community
  • 1
  • 1
Randy
  • 4,351
  • 2
  • 25
  • 46