【发布时间】:2015-07-17 14:29:19
【问题描述】:
我正在显示警报对话框,其中我有“条款和条件”,最后还有我想要获取 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
}
现在我的整个文本都是可点击的,但我只想“条款和条件”可点击,当它点击打开特定链接时。
【问题讨论】:
-
没有 Ulhas,不是您的整个页面都是可点击的。它只是“条款和条件”。虽然它在点击时抛出错误。我做了“运行代码片段”。
-
对不起@KishorPawar,但我没有在里面提供任何网址。代码在这里更改,我没有放原始代码,但你会得到我想要做的。
-
我想说的是你的代码看起来是对的。只有“条款和条件”是可点击的,而不是整个页面。
标签: android url hyperlink android-alertdialog