Fav*_*las 5 android android-alertdialog
根据我之前的问题,我仍然无法管理我的自定义上的超链接,AlertDialog但我相信我缩小了问题的范围,因为我认为它只是不起作用,因为它是一个自定义对话框.
在strings.xml我有这样定义的字符串:
<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>
Run Code Online (Sandbox Code Playgroud)
如果我以这种方式创建我的对话框:
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());
Run Code Online (Sandbox Code Playgroud)
它显示如下:

这可以按预期工作,所有点击都是可点击的.
现在我想要相同的东西,但在自定义布局上.
TextView在我的上面创建了一个info.xml:
<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" />
Run Code Online (Sandbox Code Playgroud)
这是代码:
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());
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,它显示如下(链接不可点击,甚至没有标记为链接):

如果我删除
textView.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
它显示像波纹管图像(链接标记为链接但不可点击):

我也试过用Linkify,android:autoLink="web"但结果总是一样的.
setMessage()但有一个自定义布局TextView无法使其工作.
可能这很简单,但似乎无法使它工作.有什么建议?
谢谢
您没有定义TextView android:autoLink="all",android:clickable="true"&android:linksClickable="false"
对于info.xml TextView,如下所示
<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" />
Run Code Online (Sandbox Code Playgroud)
无论如何,你的代码完美无缺,......
AlertDialog的代码:
LayoutInflater inflater = LayoutInflater.from(ctx);
View layout = inflater.inflate(R.layout.info, null);
AlertDialog.Builder about = new AlertDialog.Builder(ctx);
about.setTitle("Data");
about.setIcon(R.drawable.info);
// Make the textview clickable. Must be called after show()
TextView textView = (TextView) layout.findViewById(R.id.infoDetailText);
textView.setText(R.string.link_text_manual);
textView.setMovementMethod(LinkMovementMethod.getInstance());
about.setView(layout);
AlertDialog displayInfo = about.create();
displayInfo.show();
Run Code Online (Sandbox Code Playgroud)
TextView XML代码:
<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:padding="4dp" />
Run Code Online (Sandbox Code Playgroud)
删除了两个属性..
android:autoLink="all"
android:linksClickable="true"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6243 次 |
| 最近记录: |