Android之使用Intent跳转到一个网页
2014-12-10 22:32
411 查看
1.首先,建立一个安卓项目,项目名为IntentTest,创建完成后,打开res目录下的layout文件夹的activity_main.xml文件,进行布局,代码附上:
activity_main.xml文件:
布局文件下有两个控件,一个编辑框,一个按钮,点击按钮跳转到编辑框里面的uri地址。
2.接下来,对src目录下的包里面的MainActivity.java文件打开, 修改里面的代码,代码附上:
MainActivity.java文件:
3.这样就可以用Intent跳转到一个网页了,接下来运行此项目,运行效果如下:
在布局文件里我默认把编辑框的文本内容设置为百度的网址,接下来点击跳转网页的按钮,效果如下,其中必须保证你的计算机有网络:
这样就浏览到百度的网页了。
4.以上就是如何利用Intent浏览访问一个网页,很简单,仅供大家学习参考,写得不好,请见谅,如果有错误请指出,谢谢!
activity_main.xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textUri" android:text="http://www.baidu.com/"/> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转网页"/> </LinearLayout>
布局文件下有两个控件,一个编辑框,一个按钮,点击按钮跳转到编辑框里面的uri地址。
2.接下来,对src目录下的包里面的MainActivity.java文件打开, 修改里面的代码,代码附上:
MainActivity.java文件:
package com.example.intenttest; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { private Button button1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//设置页面布局 button1=(Button)findViewById(R.id.button1);//获取按钮控件 button1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub EditText editText1=(EditText)findViewById(R.id.editText1);//获得编辑框控件 Intent intent=new Intent();//创建Intent对象 intent.setAction(Intent.ACTION_VIEW);//为Intent设置动作 String data=editText1.getText().toString();//获取编辑框里面的文本内容 intent.setData(Uri.parse(data));//为Intent设置数据 startActivity(intent);//将Intent传递给Activity } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
3.这样就可以用Intent跳转到一个网页了,接下来运行此项目,运行效果如下:
在布局文件里我默认把编辑框的文本内容设置为百度的网址,接下来点击跳转网页的按钮,效果如下,其中必须保证你的计算机有网络:
这样就浏览到百度的网页了。
4.以上就是如何利用Intent浏览访问一个网页,很简单,仅供大家学习参考,写得不好,请见谅,如果有错误请指出,谢谢!
相关文章推荐
- Android:TextView添加下划线以及利用intent跳转到一个网页
- Android-Adapter中使用Intent跳转到一个activity
- 【Android】使用Intent实现Activity之间的跳转(创建一个Activity的过程)
- android 使用intent打开网页
- Android页面跳转Intent使用
- Android 使用Intent 在Activity 间跳转
- Android中使用Intent进行叶面的跳转
- Android成长日记-使用Intent实现页面跳转
- Android使用ListView构造复杂界面,响应点击事件,通过Intent跳转activity
- Android,使用Intent或Bundle传递参数,跳转页面
- android中使用intent来实现Activity带数据跳转
- Android使用WebView嵌入网页,网页内点击跳转到另一个网页后,返回问题解决
- Android入门(8)——使用Intent实现页面跳转
- Android使用多个Intent进行Activity跳转,如何直接退出系统
- android中使用intent来实现Activity带数据跳转
- android开发基础:Intent与Bundle的使用,实现页面跳转及信息传递
- Android应用实例之---使用Linkify + 正则式区分微博文本链接及跳转处理如同新浪微博Android版的应用上,当我们点击微博文本上的链接会自动跳转界面,或网站链接跳转网页浏览,或邮箱链接
- Android,使用Intent或Bundle传递参数,跳转页面。
- android 使用多个Intent 进行activity跳转 而没有finish的情况,如何直接退出系统
- Android中的Handler+使用Intent进行Activity间的跳转