显示吐司密码中的LockScreen [英] Display Toast in Password LockScreen

查看:107
本文介绍了显示吐司密码中的LockScreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android的默认密码的LockScreen显示吐司,如:

I want to display a Toast in Android's default Password LockScreen, such as:

Toast.makeText(getContext(), "Invalid password", Toast.LENGTH_LONG).show();

不过,这吐司实际上出现在主屏幕上,而不是锁屏。我觉得这个面包是隐藏的键盘锁。
我还发现, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 可以用来显示一些在锁屏的顶部。我的障碍是,它需要getWindow()中的活性,以设置此标志,然而,在Android框架默认的LockScreen不具有活性。 我该如何解决这个问题呢?

However, this toast actually appears in home screen instead of lockscreen. I think this toast is hidden by the keyguard.
I also found that WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED can be used to display something on top of the lockscreen. My obstacle is that it requires getWindow() in an activity to set this flag, however, default LockScreen in Android framework does not have an activity. How can I solve this issue?

推荐答案

这是我做到了......

this is how I did it....

在code执行如下..

In code do the followings..

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast,  null);  // toast is a custom layout for the toast message
Toast t= new Toast(getApplicationContext());
t.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
t.setDuration(Toast.LENGTH_SHORT);
t.setView(layout);
t.show();

我觉得这是你想要的答案。

I think this is the answer you wanted.

这篇关于显示吐司密码中的LockScreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆