2013-02-02 50 views
0

我想设置链接网址和链接来启动其他活动。 这里我的代码,其工作与HTML链接,但不知道如何做链接,将启动其他活动。我的代码如何设置链接网址+可点击文本

例如:

final AlertDialog d = new AlertDialog.Builder(this) 
      .setPositiveButton(android.R.string.ok, null) 
      .setMessage(Html.fromHtml(getResources().getString(R.string.infoAuthor)+" <br> <a href=\"https://www.youtube.com">click here for help</a>")) 
      .create(); 
      d.show(); 
      // Make the textview clickable. Must be called after show() 
      ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); 

,如果你可以提供一些代码是如何做到这一点。

回答

0

试试看post。笔者使用来完成这个过程的代码:

public static class MyOtherAlertDialog { 

public static AlertDialog create(Context context) { 
    final TextView message = new TextView(context); 
    // i.e.: R.string.dialog_message => 
      // "Test this dialog following the link to dtmilano.blogspot.com" 
    final SpannableString s = 
       new SpannableString(context.getText(R.string.dialog_message)); 
    Linkify.addLinks(s, Linkify.WEB_URLS); 
    message.setText(s); 
    message.setMovementMethod(LinkMovementMethod.getInstance()); 

    return new AlertDialog.Builder(context) 
    .setTitle(R.string.dialog_title) 
    .setCancelable(true) 
    .setIcon(android.R.drawable.ic_dialog_info) 
    .setPositiveButton(R.string.dialog_action_dismiss, null) 
    .setView(message) 
    .create(); 
} 
} 

另一种soultion从同一岗位上面的一个是这样的:

// Linkify the message 
    final SpannableString s = new SpannableString(msg); 
    Linkify.addLinks(s, Linkify.ALL); 

    final AlertDialog d = new AlertDialog.Builder(activity) 
     .setPositiveButton(android.R.string.ok, null) 
     .setIcon(R.drawable.icon) 
     .setMessage(s) 
     .create(); 

    d.show(); 

    // Make the textview clickable. Must be called after show() 
    ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); 
0
在布局XML

 <TextView 
     android:id="@+id/description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:autoLink="web|phone|email"   
     android:text="" /> 

网络

到网址,电话和电子邮件

您还可以更改颜色 android:textColorLink =“@ color/linkscolor”

从xml中膨胀您的视图并使用setView方法设置对话框视图

相关问题