<tfoot id='nHdkq'></tfoot>

  • <small id='nHdkq'></small><noframes id='nHdkq'>

      <i id='nHdkq'><tr id='nHdkq'><dt id='nHdkq'><q id='nHdkq'><span id='nHdkq'><b id='nHdkq'><form id='nHdkq'><ins id='nHdkq'></ins><ul id='nHdkq'></ul><sub id='nHdkq'></sub></form><legend id='nHdkq'></legend><bdo id='nHdkq'><pre id='nHdkq'><center id='nHdkq'></center></pre></bdo></b><th id='nHdkq'></th></span></q></dt></tr></i><div id='nHdkq'><tfoot id='nHdkq'></tfoot><dl id='nHdkq'><fieldset id='nHdkq'></fieldset></dl></div>

      • <bdo id='nHdkq'></bdo><ul id='nHdkq'></ul>
    1. <legend id='nHdkq'><style id='nHdkq'><dir id='nHdkq'><q id='nHdkq'></q></dir></style></legend>

        Android 在警报对话框中设置文本

        时间:2023-08-30

            <bdo id='Fldkz'></bdo><ul id='Fldkz'></ul>
          • <i id='Fldkz'><tr id='Fldkz'><dt id='Fldkz'><q id='Fldkz'><span id='Fldkz'><b id='Fldkz'><form id='Fldkz'><ins id='Fldkz'></ins><ul id='Fldkz'></ul><sub id='Fldkz'></sub></form><legend id='Fldkz'></legend><bdo id='Fldkz'><pre id='Fldkz'><center id='Fldkz'></center></pre></bdo></b><th id='Fldkz'></th></span></q></dt></tr></i><div id='Fldkz'><tfoot id='Fldkz'></tfoot><dl id='Fldkz'><fieldset id='Fldkz'></fieldset></dl></div>
          • <legend id='Fldkz'><style id='Fldkz'><dir id='Fldkz'><q id='Fldkz'></q></dir></style></legend>
              1. <tfoot id='Fldkz'></tfoot>

                  <tbody id='Fldkz'></tbody>

                  <small id='Fldkz'></small><noframes id='Fldkz'>

                  本文介绍了Android 在警报对话框中设置文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个警报对话框,顶部有一个图像标题,底部有 2 个按钮,我想通过代码在中间设置文本.但是,我无法在横幅下方设置文本.我想创建类似于 this link 上的内容.但是,文本总是在图像上方结束,因为我不知道如何在对话框构建器中引用文本视图.谢谢

                  I'm trying to create an alert dialog with an image header across the top, 2 buttons at the bottom and I want to set the text in the middle from code. However, I can't get the set text underneath the banner. I want to create something similar to the one on this link. However, the text always ends up above the image as I don't know how to reference the textview in the dialog builder. Thanks

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                      LayoutInflater inflater = getLayoutInflater();
                  
                      builder.setView(inflater.inflate(R.layout.custom_dialog, null))
                             .setMessage("Message" + message)
                             .setPositiveButton("Share", new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {
                                     if (isNetworkAvailable()) {
                                          if (...) {...} 
                                          else {...}
                                     } else {...} 
                                 }  
                             })
                             .setNegativeButton("Shake again!", new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {
                                     // User cancelled the dialog
                                 }
                             })
                             .setOnCancelListener(new OnCancelListener() {
                                  @Override
                                  public void onCancel(DialogInterface dialog) {}
                             });
                  
                      AlertDialog alert = builder.create();
                  
                      alert.setOnDismissListener(new OnDismissListener() {
                          @Override
                          public void onDismiss(DialogInterface dialog) {}
                      });
                  
                      alert.show();
                  

                  布局xml文件为:

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">
                  
                  <ImageView
                      android:src="@drawable/yo3"
                      android:layout_width="match_parent"
                      android:layout_height="64dp"
                      android:scaleType="center"
                      android:background="#FFFFBB33"
                      android:contentDescription="@string/app_name" />
                  
                  <TextView
                      android:id="@+id/dialogtext"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/>
                  
                  </LinearLayout>`
                  

                  推荐答案

                  不要用你的方式设置消息.

                  Don't set the message with the way you do it.

                  在您的自定义布局中,您必须设置的 textview 是dialogtext"TextView.试试这个……看看我得到了我膨胀的自定义视图,从那个视图中我得到了自定义对话框(你之前实际上没有设置)并设置消息在构建发生后显示.实际上,您可以拥有任何您想要的自定义视图,并根据自己的喜好设置视图的每个元素,甚至可以处理其上的事件

                  In your custom layout the textview you have to set is the "dialogtext" TextView. Try this...see that i get the custom view that i inflate and from that view i get the custom dialog (which you didn't actualy set before) and set the message to show after the build has taken place. Actually you can have whatever custom view you want and set each element of the view as you prefer or even handle events on it

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                  LayoutInflater inflater = getLayoutInflater();
                  
                  View customView = inflater.inflate(R.layout.custom_dialog, null);
                  TextView messageView = (TextView)customView.findViewById(R.id.dialogtext);
                  
                  
                  builder.setView(customView)
                          .setPositiveButton("Share", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {
                  
                                 if (isNetworkAvailable()){
                  
                                      if (......;
                  
                                      } else {
                                          ......
                                      }
                  
                                 } else {
                                     .......;
                                 }    
                             }  
                         })
                         .setNegativeButton("Shake again!", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {
                                 // User cancelled the dialog
                  
                             }
                  
                      }).setOnCancelListener(new OnCancelListener() {
                  
                          @Override
                          public void onCancel(DialogInterface dialog) {
                  
                          }
                      });
                  
                  messageView.SetText("Message" + message);
                  
                  
                  
                  AlertDialog alert = builder.create();
                  
                  alert.setOnDismissListener(new OnDismissListener() {
                  
                      @Override
                      public void onDismiss(DialogInterface dialog) {
                  
                  
                      }
                  });
                  alert.show();
                  

                  这篇关于Android 在警报对话框中设置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android:对话框关闭而不调用关闭 下一篇:在代码和资源中设置 TextView 字体大小时不一致

                  相关文章

                  最新文章

                  1. <tfoot id='A3NR2'></tfoot>

                      • <bdo id='A3NR2'></bdo><ul id='A3NR2'></ul>

                    1. <small id='A3NR2'></small><noframes id='A3NR2'>

                    2. <legend id='A3NR2'><style id='A3NR2'><dir id='A3NR2'><q id='A3NR2'></q></dir></style></legend>

                      <i id='A3NR2'><tr id='A3NR2'><dt id='A3NR2'><q id='A3NR2'><span id='A3NR2'><b id='A3NR2'><form id='A3NR2'><ins id='A3NR2'></ins><ul id='A3NR2'></ul><sub id='A3NR2'></sub></form><legend id='A3NR2'></legend><bdo id='A3NR2'><pre id='A3NR2'><center id='A3NR2'></center></pre></bdo></b><th id='A3NR2'></th></span></q></dt></tr></i><div id='A3NR2'><tfoot id='A3NR2'></tfoot><dl id='A3NR2'><fieldset id='A3NR2'></fieldset></dl></div>