在锁定屏幕上显示

在锁定屏幕上显示

如何在锁定屏幕上显示TextViewEditView
我已经尝试过了,并且还在布局中添加了TextView,但没有任何反应

@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_lock);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);



  }


然后我尝试了这个(在Service中),它也没有用

@Override
    public void onCreate() {
WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_FULLSCREEN
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | PixelFormat.TRANSLUCENT);

    TextView textView = new TextView(this);
    textView.setId('1');
    textView.setText("This is a demo");
    textView.setTextSize(15);
    textView.setGravity(Gravity.CENTER);

    WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    mWindowManager.addView(textView, mLayoutParams);

 }


请帮帮我

最佳答案

您需要这样做:

wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                80, 80, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT
                );
        params.gravity = Gravity.CENTER;
        params.setTitle("text params");

        wm.addView(YourTextView, params);

关于android - 在锁定屏幕上显示文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34258379/

10-10 21:48