【问题标题】:Android: Clickable hyperlinks in DialogPreferenceAndroid:DialogPreference 中的可点击超链接
【发布时间】:2010-11-28 13:49:40
【问题描述】:

我要完成的工作:在 DialogPreference 显示的消息文本中创建一个可点击的超链接。

到目前为止我的解决方案: 关注这个话题:link,我完成了在 DialogPreference 中显示的格式化超链接,但是这个超链接不可点击。

问题:如何在 DialogPreference 中使超链接可点击。

我的代码:

public class AboutDialog extends DialogPreference {
public AboutDialog(Context oContext, AttributeSet attrs)
{
    super(oContext, attrs);
    final SpannableString s = new SpannableString(oContext.getText(R.string.about_text));
    Linkify.addLinks(s, Linkify.ALL);
    this.setDialogMessage(s);
}}

【问题讨论】:

    标签: android user-interface hyperlink


    【解决方案1】:

    好吧,我不确定,但试试这个:

    • 创建 textView,使用 yourTextVeiw.setText(s) 将字符串设置为文本
    • 为此 textView 设置 onClickListener
    • 现在将此 textView 设置为对话框,尝试使用 addView(textview) 方法。

    【讨论】:

    • viv,非常感谢您的回复。但它不起作用。 DialogPreference 只有 onBindView(View)。我按照你的方法尝试了各种方法,但它不起作用。现在我尝试使用其他 API 接管 DialogPreference :)
    • 你是个好人。我想在 PreferenceScreen 中完成一个“关于”对话框,并在“关于”对话框中添加一个可点击的超链接,所以我卡在那里:)
    • 好吧 ycz,这对我来说有点棘手,有一个 onCreateDialogView(),返回 View 的方法,所以如果它可以被覆盖,但只是澄清一件事,你想在某些对话框类型的视图中显示超链接或仅在 DialogPreference 中显示超链接,它(DialogPreference)是否非常强制性,我的意思是为什么不使用简单的对话框 ....
    • -_-!因为My App的主菜单已经有4个图标了,我很懒,不会为“关于对话框”画新的图标。我做了很多搜索“如何在 Preferencescreen 中创建对话框”,但我只是发现使用 DialogPreference。好吧,看来我会做一些艺术工作:)
    • 哈哈,好吧,我目前对 DialogPreference 感到无助,以防将来如果您无法使用 DialogPrefernce 解决任何问题,您可以通过简单的对话框来解决,我也将能够在这种情况下提供帮助,因为我经常使用它们,以后在这里发表评论,我会收到通知,希望你得到你想要实现的目标,上帝保佑你....
    【解决方案2】:

    这似乎有效

    package net.anei.cadpage.preferences;
    
    import android.content.Context;
    import android.os.Bundle;
    import android.text.SpannableString;
    import android.text.method.LinkMovementMethod;
    import android.text.util.Linkify;
    import android.util.AttributeSet;
    import android.view.View;
    import android.widget.TextView;
    
    public class DialogPreference extends android.preference.DialogPreference {
      public DialogPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
      }
    
      public DialogPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
      }
    
      @Override
      protected View onCreateDialogView() {
        final SpannableString s = new SpannableString(getDialogMessage());
        Linkify.addLinks(s, Linkify.WEB_URLS);
        final TextView view = new TextView(getContext());
        view.setText(s);
        view.setMovementMethod(LinkMovementMethod.getInstance());
        return view;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 2016-04-20
      • 2020-12-04
      • 2010-10-26
      • 2014-01-21
      • 2012-10-21
      相关资源
      最近更新 更多