单击android中的按钮时如何重定向到特定的URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2236413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:05:39 来源:igfitidea点击:
how to redirect to particular URL while clicking on button in android?
提问by deepthi
I want to redirect user to particular URL while clicking on Button
in Android App.
我想在点击Button
Android 应用程序时将用户重定向到特定的 URL 。
回答by ziya
You can start a 'view' activity, which would be the browser given a URL:
您可以启动“查看”活动,这将是给定 URL 的浏览器:
public class HelloWorld extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Assuming you are using xml layout
Button button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("http://www.stackoverflow.com/"));
startActivity(viewIntent);
}
});
}
}