无法删除android中状态栏的添加视图

时间:2015-09-03 09:03:54

标签: android android-view android-windowmanager

我正在尝试阻止状态栏,我通过向状态栏添加视图来成功完成此操作。我试图在检测到onClick时删除添加的视图,但视图仍然存在,我无法删除视图。任何人都可以让我知道我错过了什么。当前代码如下所示:

@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类:

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

0 个答案:

没有答案