Android: Clickable hyperlinks in DialogPreference
What I'm trying to accomplish: create a clickabel hyperlink in the message text displayed by a DialogPreference.
My solution so far: follow this topic: link , and I am accomplished a formating hyperlink displayed in the DialogPreference, but this hyperlink not clickable.
Question:How to make the hyperlink clickable in the DialogPreference.
my code:
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.setDialogMes开发者_如何学JAVAsage(s);
}}
Well, I am not sure but try this :
- Create textView, set your string s as it's text, using yourTextVeiw.setText(s)
- set onClickListener for this textView
- Now set this textView into dialog, try using addView(textview) , method.
This seems to work
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;
}
}
精彩评论