gpt4 book ai didi

java - 不允许单击外部对话框

转载 作者:搜寻专家 更新时间:2023-11-01 09:19:04 26 4
gpt4 key购买 nike

<分区>

我想看看用户是否有互联网。当用户没有互联网时,它会显示一个带有消息的对话框,但如果他触摸对话框以外的地方,该对话框将不执行任何操作。

我试过:

dialog.setCancelable(false);

dialog.setCanceledOnTouchOutside(false);

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if(!isConnected())
{
new AlertDialog.Builder(this)
.setTitle("No internet")
.setMessage("Message ")
.setPositiveButton("Close", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int w) {
finish();
}
})
.show();
}
}
private boolean isConnected()
{
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

return networkInfo != null && networkInfo.isConnected();
}

}

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