我正在显示Alert-Dialog,其中我有“条款和条件”,最后有文本,点击我想要获取URL。 我不想在String而不是URL中显示URL我想以不同的颜色或大小显示String以了解用户。
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
}
现在我的全文是可点击的,但我只想“条款和条件”可点击,当它点击打开特定链接时。
答案 0 :(得分:2)
我不确定它是否会起作用,但你可以试试这个
text.setText(Html.fromHtml("<bMy Text is going here....</b>" +
"<a href=\"http://www.example.com\">Terms and Conditions.</a> "));
text.setMovementMethod(LinkMovementMethod.getInstance());