Android textview链接并打开webview
刚刚在android上完成hello world 我只想问: 如何将textview作为链接,并将链接连接到webview页面以显示数据 或者,是否可以创建一个textview链接,单击该链接后,将打开另一个textview 对不起,伙计们,我现在真的不太了解androidAndroid textview链接并打开webview,android,textview,android-webview,Android,Textview,Android Webview,刚刚在android上完成hello world 我只想问: 如何将textview作为链接,并将链接连接到webview页面以显示数据 或者,是否可以创建一个textview链接,单击该链接后,将打开另一个textview 对不起,伙计们,我现在真的不太了解android 非常感谢您的任何意见。谢谢。:) 此行应使用指定的url打开内置浏览器: startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://
非常感谢您的任何意见。谢谢。:) 此行应使用指定的url打开内置浏览器:
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.google.com")));
您的活动应该包含以下部分:
//define class variables here
TextView tv;
protected void onCreate(Bundle savedInstanceState)
{
//some code of yours
tv=(TextView)findViewById(R.id.tv);
tv.setOnClickListener(this);
//more code of yours
}
//whatever else you have in your source code
public void onClick(View v)
{
//handle the click events here, in this case open www.google.com with the default browser
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.google.com")));
}
这可能不是100%准确的语法,因为我只是自己写的,但你明白了。谢谢巴迪的想法 在网上搜索了几次之后。我有这个代码,它似乎工作
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first); // Our only layout for this app is main.xml
// Initialize the UI components
changingTextView = (TextView) findViewById(R.id.textView1);
final TextView view = (TextView) findViewById(R.id.textView1);
view.setOnClickListener(this);
public void onClick(View v) { // Parameter v stands for the view that was clicked.
if(v.getId() == R.id.textView1){
Toast.makeText(this, "Textview Link Testing!",
Toast.LENGTH_LONG).show();
}
// getId() returns this view's identifier.
if(v.getId() == R.id.leftButton){
// setText() sets the string value of the TextView
changingTextView.setText("You clicked this button1");
}else if(v.getId() == R.id.rightButton){
changingTextView.setText("You clicked this button2");
WebView page = (WebView) findViewById(R.id.webView1);
String text = "<html><head>"
+ "<style type=\"text/css\">body{color: #ffdec2; background-color: #1F0C01;}"
+ "</style></head>"
+ "<body>"
+ "<p align=\"justify\">"
+ getString(R.string.multistring)
+ "</p> "
+ "<p align=\"justify\">"
+ getString(R.string.multistring1)
+ "</p> "
+ "</body></html>";
page.loadData(text, "text/html", "utf-8");
}
}
}
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);//此应用程序的唯一布局是main.xml
//初始化UI组件
changingTextView=(TextView)findViewById(R.id.textView1);
最终文本视图=(文本视图)findViewById(R.id.textView1);
view.setOnClickListener(这个);
public void onClick(视图v){//参数v表示单击的视图。
如果(v.getId()==R.id.textView1){
Toast.makeText(这是“Textview链接测试!”,
Toast.LENGTH_LONG).show();
}
//getId()返回此视图的标识符。
if(v.getId()==R.id.leftButton){
//setText()设置TextView的字符串值
changingTextView.setText(“您单击了此按钮1”);
}else if(v.getId()==R.id.rightButton){
changingTextView.setText(“您单击了此按钮2”);
WebView页面=(WebView)findViewById(R.id.webView1);
String text=“”
+“正文{color:#ffdec2;背景色:#1F0C01;}”
+ ""
+ ""
+“”
+getString(R.string.multistring)
+“
”
+“”
+getString(R.string.multistring1)
+“
”
+ "";
页面加载数据(文本,“文本/html”、“utf-8”);
}
}
}