• android中使用WebView浏览网页


    布局文件如下:

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="vertical"
     6     tools:context=".MainActivity" >
     7 
     8     <EditText
     9         android:id="@+id/url"
    10         android:layout_width="match_parent"
    11         android:layout_height="wrap_content" />
    12 
    13     <Button
    14         android:id="@+id/search"
    15         android:layout_width="match_parent"
    16         android:layout_height="wrap_content" 
    17         android:text="搜索"/>
    18 
    19     <WebView
    20         android:id="@+id/show"
    21         android:layout_width="match_parent"
    22         android:layout_height="match_parent" />
    23 
    24 </LinearLayout>

    然后是mainactivity中代码:

     1 public class MainActivity extends Activity {
     2     EditText url;
     3     WebView show;
     4     Button search;
     5 
     6     @Override
     7     protected void onCreate(Bundle savedInstanceState) {
     8         super.onCreate(savedInstanceState);
     9         setContentView(R.layout.activity_main);
    10         url = (EditText) findViewById(R.id.url);
    11         show = (WebView) findViewById(R.id.show);
    12         search = (Button) findViewById(R.id.search);
    13         search.setOnClickListener(new OnClickListener() {
    14             
    15             public void onClick(View v) {
    16                 String urlStr = url.getText().toString();
    17                 show.loadUrl(urlStr);
    18             }
    19         });
    20     }
    21 
    22 }

    由于要联网,在androidmanifest配置文件中加入网络访问权限:

      <uses-permission android:name="android.permission.INTERNET"/>;

  • 相关阅读:
    CMD 已存在的表, 没有主键的 添加主键属性
    回调函数 call_back
    在Ubuntu下安装MySQL,并将它连接到Navicat for Mysql
    F查询和Q查询,事务及其他
    Djabgo ORM
    Diango 模板层
    Django视图系统
    Django简介
    Web 框架
    HTTP协议
  • 原文地址:https://www.cnblogs.com/baorantHome/p/6905240.html
Copyright © 2020-2023  润新知