首页 > 代码库 > 【Android N 7.1.1】 锁屏之上显示Toast
【Android N 7.1.1】 锁屏之上显示Toast
package com.android.systemuirom.keyguard; import android.content.Context; import android.view.Gravity; import android.view.WindowManager; import android.widget.Toast; public class KeyguardToast { private static KeyguardToast sInstance; private Toast mToast = null; public static KeyguardToast getInstance() { if (sInstance == null) { sInstance = new KeyguardToast(); } return sInstance; } private KeyguardToast() { // ignore } public Toast makeText(Context context, CharSequence text, int duration, boolean needOffsetPosition) { if (mToast != null) { mToast.cancel(); mToast = null; } mToast = Toast.makeText(context, text, duration); mToast.getWindowParams().type = WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; mToast.getWindowParams().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; mToast.getWindowParams().flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; // Toast偏移位置 if (needOffsetPosition) { // set offset position mToast.setGravity(Gravity.CENTER, 0, -300); } return mToast; } public void cancelToast() { if (mToast != null) { mToast.cancel(); mToast = null; } } }
【Android N 7.1.1】 锁屏之上显示Toast
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。