我正在显示警报对话框,其中有“条款和条件”,最后有一个文本,点击我想获取 URL。 我不想在字符串中显示 URL,而不是 URL,我想以不同的颜色或大小显示字符串以了解用户。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My App Title");
builder.setPositiveButton(R.string.next,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// code goes here
User u = new User();
u.setTncAccpted(true);
u.setFirstRun(true);
u.commit(SelectionApp.this);
viewedWeb = false;
dialog.dismiss();
}
});
try {
builder.setMessage(Html
.fromHtml("<p>My Text is going here....</p><p>My other String is going here....</p>By proceeding you are accepting <a href=\"\">Terms and Conditions.</a>"));
AlertDialog dialog = builder.create();
if (dialog == null)
return;
dialog.show();
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
((TextView) dialog.findViewById(android.R.id.message))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent termAndConditionIntent = new Intent(
SelectionWhiteApp.this, ViewWeb.class);
startActivity(termAndConditionIntent);
}
});
} catch (Exception e) {
// TODO: handle exception
}
现在我的整个文本都是可点击的,但我只想“条款和条件”可点击,并且当它点击时打开特定链接。
最佳答案
我不确定它是否有效,但你可以尝试一下
text.setText(Html.fromHtml("<bMy Text is going here....</b>" +
"<a href=\"http://www.example.com\">Terms and Conditions.</a> "));
text.setMovementMethod(LinkMovementMethod.getInstance());
关于android - 我如何在 AlertDialog 中使用 String 制作 String + URL 不可点击,而 URL 可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30093912/