1

I am trying to block status bar and I am successful in doing that by adding a view to status bar. I am trying to remove the added view when onClick is detected, but the view still remains and I am not able to remove the view. Can any one please let me know what am I missing. The current code is as shown below:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

         manager = ((WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE));

     localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

                // this is to enable the notification to recieve touch events
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

                // Draws over status bar
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = (int) (50 * getResources()
                .getDisplayMetrics().scaledDensity);
        localLayoutParams.format = PixelFormat.TRANSPARENT;

         view = new customViewGroup(this);

        manager.addView(view, localLayoutParams);

//      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);

        m_activateButton = (Button)findViewById(R.id.button);
        m_activateButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                 if(manager != null){
                        manager.removeView(view);
                        }
                }});



     }

CustomView Class:

public class customViewGroup extends ViewGroup {

    public customViewGroup(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Log.v("customViewGroup", "**********Intercepted");
        return true;
    }
}
8
  • try to do this on a runonUIThread as follows : this.runOnUiThread(new Runnable() { @Override public void run() { manager.removeView(view); } }); otherwise instead of manager, you can try : ((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(view); Sep 3, 2015 at 9:17
  • Explain a little bit, you have tried my code and it's giving any error? Sep 3, 2015 at 9:41
  • @Skizo I have tried it, not able to remove view and no error either. If I try to use the same lines used in onCreate and if I say manager.removeView() it says view is not attached to Window. Sep 3, 2015 at 9:46
  • Post your customView pls Sep 3, 2015 at 9:52
  • @Skizo Updated code with customView class Sep 3, 2015 at 9:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.