Steve
Steve

Reputation: 49

show text over lock screen

How can I show TextView and EditView over the lock screen? I've tried this and I also add TextView in the layout but nothing has happened

@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);



  }

then I tried this (in Service) and it didn't work too

@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);

 }

Help me please

Upvotes: 2

Views: 503

Answers (1)

j2emanue
j2emanue

Reputation: 62539

you need to do it like this:

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

Upvotes: 1

Related Questions