【问题标题】:Custom Dialog for no internet access没有互联网访问的自定义对话框
【发布时间】:2016-02-05 00:30:59
【问题描述】:

我想创建类似这个图片的对话框,谁能帮帮我

【问题讨论】:

标签: android dialog


【解决方案1】:

您可以创建一个警报对话框来执行此操作。像这样的东西应该工作。

AlertDialog dialog = new AlertDialog.Builder(mContext)
        .setTitle("Connection Failed")
        .setMessage("Please Check Your Internet Connection")
        .setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                   //Code for try again 
                }
            })
        .setNegativeButton("Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            }).create();
dialog.show(); 

【讨论】:

    【解决方案2】:

    在这里您可以找到有关如何构建对话框的参考

    http://developer.android.com/guide/topics/ui/dialogs.html

    这是一个可以帮助您检测互联网访问的代码 sn-p:

    http://www.androidsnippets.org/snippets/131/

    【讨论】:

      【解决方案3】:

      首先您需要检查连接,为此添加以下类。 类 ConnectionDetector:

        public class ConnectionDetector {
      
          private Context _context;
      
          public ConnectionDetector(Context context) {
              this._context = context;
          }
      
          public boolean isConnectingToInternet() {
              ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
              if (connectivity != null) {
                  NetworkInfo[] info = connectivity.getAllNetworkInfo();
                  if (info != null)
                      for (int i = 0; i < info.length; i++)
                          if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                              return true;
                          }
      
              }
              return false;
          }
      
      }
      

      然后检查 ConnectionDetector 的结果并显示警报对话框。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-31
        • 2017-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多