刚刚在android上完成了hello world。
只想问: 如何将textview作为链接并将链接连接到webview页面以显示数据?
或者是否可以制作文本视图链接,点击链接后会打开另一个文本视图?
对不起伙计们,我现在对android很不了解。
非常感谢任何输入。谢谢。 :)
答案 0 :(得分:0)
此行应使用指定的网址打开您的内置浏览器:
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%准确的语法,因为我只是自己写这个,但你明白了。
答案 1 :(得分:0)
感谢好友的想法
在网上搜索了几下之后。我有这个代码,它似乎工作。@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");
}
}
}