向windowmanager添加按钮

时间:2016-03-31 06:44:15

标签: android

我想制作一个锁屏应用,我使用叠加窗口。但是,如果我想在窗口管理器中添加一些按钮,我该怎么办。当用户按下按钮后,我应该使用哪个命令?

我的代码:

DisplayMetrics metrics = getResources().getDisplayMetrics();
        int densityDpi = (int)(metrics.density * 160f);
        LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        mTopView = (RelativeLayout) li.inflate(R.layout.red_layout, null, false);
int LayoutParamFlags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                densityDpi * 4,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                LayoutParamFlags,
                PixelFormat.TRANSLUCENT);
        windowManager.addView(mTopView,params);

谢谢。

0 个答案:

没有答案