【问题标题】:How to include link url in Alertdialog in .setMessage Android Code如何在 .setMessage Android 代码中的 Alertdialog 中包含链接 url
【发布时间】:2015-09-21 23:37:49
【问题描述】:

它正在添加指向存储在外部 url 中的 cookie 策略的链接。但不像在文本中添加链接。帮我在文本中添加一个 url,到策略 url。谢谢

@Override
  public void onStart() {
    super.onStart();
    final SharedPreferences settings =
        getSharedPreferences("localPreferences", MODE_PRIVATE);
    if (settings.getBoolean("isFirstRun", true)) {
      new AlertDialog.Builder(this)
        .setTitle("Cookies")
        .setMessage("On this site device identifiers are used to personalize content and ads,"
                + " in order to provide social media features and to analyze traffic. "
                + "We also share these identifiers and other information on your device with our social media partners, "
                + "advertising and web analytics./// En este sitio se usan identificadores de dispositivo"
                + " para personalizar el contenido y los anuncios, con el fin de ofrecer funciones de medios sociales"
                + " y para analizar el tráfico. Además, compartimos estos identificadores y otra información"
                + " sobre su dispositivo con nuestros partners de medios sociales,"
                + " de publicidad y de análisis web. http://www.urlaboutcookiepolicy.com")
        .setNeutralButton("Close message", new OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            settings.edit().putBoolean("isFirstRun", false).commit();
          }
        }).show();

    }
  }

【问题讨论】:

  • 检查我的答案你会知道的

标签: android cookies


【解决方案1】:

使用以下代码在对话框中创建超链接。

TextView text=new TextView(this);
                text.setText(Html.fromHtml("<ahref=\"http://www.urlaboutcookiepolicy.com \">http://www.urlaboutcookiepolicy.com </a>"));
                text.setMovementMethod(LinkMovementMethod.getInstance());
                new AlertDialog.Builder(this)
                .setTitle("Cookies")
                .setView(text)
                .setNeutralButton("Ok",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                }).show();

【讨论】:

    【解决方案2】:

    我不确定您要问什么,但我假设您希望 URL 成为超链接。

    您将不得不为对话框定义自定义布局:http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

    然后您需要将android:autoLink="web" 添加到您的布局中。

    最后,用标签包围你的超链接:

    <a href="http://www.urlaboutcookiepolicy.com">http://www.urlaboutcookiepolicy.com</a>
    

    【讨论】:

      猜你喜欢
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      相关资源
      最近更新 更多