如何在锁定屏幕上显示TextView
和EditView
?
我已经尝试了这个,我还在布局中添加了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);
}
请帮帮我
答案 0 :(得分:1)
你需要这样做:
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);