在自定义AlertDialog无法点击的TextView的Android的超链接 [英] Android hyperlinks on TextView in custom AlertDialog not clickable
问题描述
随着我的previous问题,我仍然有我的自定义管理链接的问题 AlertDialog
,但我相信我缩小的问题,因为我觉得它不仅没有工作,因为它是自定义对话框。
我已经照着所有的说明<一href="http://stackoverflow.com/questions/1997328/android-clickable-hyperlinks-in-alertdialog">here和<一href="http://stackoverflow.com/questions/2795300/how-to-implement-a-custom-alertdialog-view">here但似乎无法绕过这种情况
在的strings.xml
我有一个字符串定义是这样的:
&LT;字符串名称=link_text_manual&GT;&LT; B&GT;文本2:&LT; / B&GT;这是某些其他
文本,具有与所述; A HREF =http://www.google.com&GT;链路其中; / a取代;指定
通过与放大器;其中;一个与安培; GT;标签。使用\电话:\网址
到&lt; A HREF =电话:4155551212&gt;拨打一个电话号码和LT; / a取代。
&LT; /串&GT;
如果我创造我的对话是这样的:
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(数据)
.setIcon(R.drawable.info)
.setMessage(R.string.link_text_manual)
.setCancelable(真)
.setNegativeButton(OK,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话框,INT ID){
dialog.dismiss();
}
});
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
//使TextView的点击。演出后,必须调用()
((TextView)welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
它显示是这样的:
这工作正常,所有的点击点击。
现在我希望同样的事情,但在自定义布局。
创建一个的TextView
我的 info.xml
是这样的:
&LT;的TextView
机器人:ID =@ + ID / infoDetailText
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:layout_below =@ + ID / infoVersionTitle
机器人:自动链接=所有
机器人:linksClickable =真
机器人:填充=4DP/&GT;
这是code:
上下文CTX =这一点;
LayoutInflater充气=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
查看布局= inflater.inflate(R.layout.info,(ViewGroup中)findViewById(R.id.infoLayout));
AlertDialog.Builder约=新AlertDialog.Builder(CTX);
about.setView(布局);
about.setTitle(数据);
about.setIcon(R.drawable.info);
AlertDialog displayInfo = about.create();
displayInfo.show();
//使TextView的点击。演出后,必须调用()
TextView中的TextView =(TextView中)displayInfo.findViewById(R.id.infoDetailText);
textView.setText(R.string.link_text_manual);
textView.setMovementMethod(LinkMovementMethod.getInstance());
通过上面的code也这样表示(链接无法点击,甚至没有被标记为链接):
如果我删除
textView.setMovementMethod(LinkMovementMethod.getInstance());
这表明像波纹图像(链接标记为链接,但无法点击):
我也试过用 Linkify
和安卓自动链接=网络
,但结果总是相同。
setMessage()
的作品,但与一个的TextView
不能让它工作。<自定义布局/ P>
也许这很简单,但似乎无法使它发挥作用。有什么建议?
感谢
您定义的TextView中没有安卓自动链接=所有
,安卓:点击=真正的
&放大器; 安卓linksClickable =假
有关info.xml的TextView如下
&LT; TextView中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / infoDetailText
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=4DP/&GT;
Following my previous question I still have problems managing hyperlinks on my custom AlertDialog
but I believe I narrowed down the problem because I think it only not works because it's a custom dialog.
I have followed all the instructions here and here but can't seem to bypass this situation
On strings.xml
I have a string defined this way:
<string name="link_text_manual"><b>text2:</b> This is some other
text, with a <a href="http://www.google.com">link</a> specified
via an <a> tag. Use a \"tel:\" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
If I create my dialog this way:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Data")
.setIcon(R.drawable.info)
.setMessage(R.string.link_text_manual)
.setCancelable(true)
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
// Make the textview clickable. Must be called after show()
((TextView)welcomeAlert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
it shows like this:
This works as expected and all clicks are clickable.
Now I want the same thing but on a custom layout.
Created a TextView
on my info.xml
like this:
<TextView
android:id="@+id/infoDetailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/infoVersionTitle"
android:autoLink="all"
android:linksClickable="true"
android:padding="4dp" />
And this is the code:
Context ctx = this;
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.info, (ViewGroup) findViewById(R.id.infoLayout));
AlertDialog.Builder about = new AlertDialog.Builder(ctx);
about.setView(layout);
about.setTitle("Data");
about.setIcon(R.drawable.info);
AlertDialog displayInfo = about.create();
displayInfo.show();
// Make the textview clickable. Must be called after show()
TextView textView = (TextView) displayInfo.findViewById(R.id.infoDetailText);
textView.setText(R.string.link_text_manual);
textView.setMovementMethod(LinkMovementMethod.getInstance());
With the above code it shows like this (links not clickable and even not marked as links):
If I remove
textView.setMovementMethod(LinkMovementMethod.getInstance());
it shows like the bellow image (Links marked as links but not clickable):
I've also tried to use Linkify
and android:autoLink="web"
but the result is always the same.
setMessage()
works but with a custom layout with a TextView
can't make it to work.
Probably this is simple but can't seem to make it work. Any suggestions?
Thanks
You defined the TextView without android:autoLink="all"
, android:clickable="true"
& android:linksClickable="false"
For info.xml TextView as below
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/infoDetailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp" />
这篇关于在自定义AlertDialog无法点击的TextView的Android的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!