如何在锁屏上显示Toast?

时间:2013-02-04 05:09:45

标签: android toast lockscreen

当前:

Toast toast = Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();

Toast在空闲屏幕上显示。但它不会出现在锁定屏幕上。

我想在锁定屏幕上显示Toast。如何...?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我在我的Activity的视图中添加了TextView,取代了Android Framework的Toast。也就是说:我自己实施了Toast。

TextView mCustomToast = (TextView)findViewById(R.id.tv_custom_toast);
/**
 * show custom toast:
 * fix the problem that {@link android.widget.Toast} can't show when screen be 
   locked
 */
private void showCustomToast() {
    if (mCustomToast != null) {
        if (mCustomToast.getVisibility() == View.VISIBLE) {
            return;
        }
        mCustomToast.setVisibility(View.VISIBLE);
        mCustomToast.postDelayed(new Runnable() {
            @Override
            public void run() {
                mCustomToast.setVisibility(View.GONE);
            }
        }, 1000);
    }
}