Android 奥利奥上的祝酒词重叠问题(8.1)
我对敬酒有意见。对于API26及以下版本,祝酒词被正确显示(下一个祝酒词等待上一个祝酒词消失),但在安卓8.1(API27)上,它们相互覆盖。我的通知通道设置如下:Android 奥利奥上的祝酒词重叠问题(8.1),android,android-8.1-oreo,Android,Android 8.1 Oreo,我对敬酒有意见。对于API26及以下版本,祝酒词被正确显示(下一个祝酒词等待上一个祝酒词消失),但在安卓8.1(API27)上,它们相互覆盖。我的通知通道设置如下: if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANN
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(notificationChannel);
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
}
这修复了我在8.0上的祝酒,但在8.1上它们仍然重叠
有没有办法解决这个问题,而不是记住上次使用的吐司并手动取消它
编辑:
来自的解决方案不起作用
/**
* <strong>public void showAToast (String st)</strong></br>
* this little method displays a toast on the screen.</br>
* it checks if a toast is currently visible</br>
* if so </br>
* ... it "sets" the new text</br>
* else</br>
* ... it "makes" the new text</br>
* and "shows" either or
* @param st the string to be toasted
*/
public void showAToast (String st){ //"Toast toast" is declared in the class
try{ toast.getView().isShown(); // true if visible
toast.setText(st);
} catch (Exception e) { // invisible if exception
toast = Toast.makeText(theContext, st, toastDuration);
}
toast.show(); //finally display it
}
/**
*公共空间显示列表(字符串st)
*这个小方法在屏幕上显示祝酒词
*它检查当前是否可以看到祝酒词
*如果是的话
* ... 它“设置”了新文本
*否则
* ... 它“创造”了新的文本
*和“显示”或
*@param st要烤的绳子
*/
public void showAToast(String st){//“Toast Toast”在类中声明
尝试{toast.getView().isShown();//如果可见,则为true
toast.setText(st);
}捕获(异常e){//如果异常则不可见
toast=toast.makeText(上下文,st,toast持续时间);
}
toast.show();//最后显示它
}
烤面包仍然覆盖在上面
编辑2:
我已经在Android问题跟踪器上为这个bug创建了一个故事:
可能与7.1版本重复是的,我认为这是一个错误。感谢您的发帖。您的问题中通知通道和Toast之间的关系是什么?@由于Android 8.0及以上版本,您需要设置适当的通知通道,以避免开发人员警告Toast(浓缩咖啡自动化测试中的一个潜在问题)。更多信息:我知道频道用于通知,但我认为它与
Toast
无关,因为您在Toast中不使用频道id。系统会用祝酒词通知您有关频道的错误,但这并不意味着祝酒词节目需要该频道。Toast
是否需要频道?
private static final int TIME_DELAY = 4000;
private static long lastToastShowTime = 0;
showToast(final String msg, final Context ctx){
final long pastTime = System.currentTimeMillis() - lastToastShowTime;
if(pastTime > TIME_DELAY ){
Toast.makeText(ctx, msg, Toast.LENGTH_LONG).show();
lastToastShowTime = System.currentTimeMillis();
}else{
final long delay = TIME_DELAY - pastTime;
lastToastShowTime = System.currentTimeMillis() + delay;
postDelayed(new Runnable(
@Override
public void run() {
try{
Toast.makeText(ctx, msg, Toast.LENGTH_LONG).show();
catch(Exception e){
Log.e("TOAST_NOT_SHOWED", "Toast not showed: " + msg, e);
}
}
), delay);
}
}