gpt4 book ai didi

java - 如何在每个 Activity 的顶部显示一条消息?

转载 作者:行者123 更新时间:2023-12-02 10:15:50 24 4
gpt4 key购买 nike

我正在检查应用程序中的互联网连接,当无法访问互联网时,我想向用户显示一条小的弹出消息,表明您处于离线状态。

我尝试使用 AlertDialogAlertDialog.Builder 来解决该问题,并且我还在互联网上搜索了不同的解决方案,但没有解决方案解决我的问题。我正在尝试通过以下方法来做到这一点。

AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
View alertdialog = inflater.inflate(R.layout.nointernetdialogue, null);
builder.setView(alertdialog);
AlertDialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams alertTop = dialog.getWindow().getAttributes();
alertTop.gravity = Gravity.TOP | Gravity.START;
alertTop.x = 100;
alertTop.y = 100;
dialog.show();

我想要的结果。

最佳答案

创建 BaseActivity,它将实现有关网络连接检查的广播接收器。每当网络连接断开时,显示 SnackBar/Alert。让您的所有其他 Activity 扩展此基本 Activity 。

关于java - 如何在每个 Activity 的顶部显示一条消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54689910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com