在一个TextView单击时在浏览器中打开链接之前打开一个弹出/警报 [英] Open a popup/alert before opening a link in the browser when clicked on a textview
本文介绍了在一个TextView单击时在浏览器中打开链接之前打开一个弹出/警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用 Html.fromHtml(串)
数据填充到TextView中。
通过设置 textview.setMovementMethod(LinkMovementMethod.getInstance())
来TextView的,它会打开在浏览器中提供的数据自动的任何链接。但是,我想打开一个弹出窗口,使用户可以选择继续打开链接或取消该过程。
I'm using Html.fromHtml(string)
to populate data into textview.
By setting the textview.setMovementMethod(LinkMovementMethod.getInstance())
to the textview, it opens any links provided in the data automatically in the browser. But, I want to open a popup giving the user the option to continue with opening the link or cancel the process.
推荐答案
您可以编写下面code:
You can write the below code:
textView.setOnClickListener(new OnClickListener(){
Builder builder = new AlertDialog.Builder(context);
AlertDialog alert = builder.create();
alert.setButton(AlertDialog.BUTTON_POSITIVE, "OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//YOUR CODE TO OPEN LINK IN WEBVIEW
alert.dismiss();
}
});
alert.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alert.dismiss();
}
});
alert.setTitle("ANY TITLE");
alert.setMessage("ANY MESSAGE");
alert.show();
});
希望它会帮助你。
Hope it will help you.
这篇关于在一个TextView单击时在浏览器中打开链接之前打开一个弹出/警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文