码迷,mamicode.com
首页 > 移动开发 > 详细

android webview

时间:2015-05-23 19:55:37      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="mydemo.mycom.demo2.WebViw">

    <ScrollView
        android:layout_weight="1000"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">


        <WebView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/wv">

        </WebView>

        </ScrollView>
    <EditText
        android:hint="webview地址"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="http://192.168.1.1:100/ProductInfo/Detail/E618923F06B644BFAA86AB274AF02358"
        android:id="@+id/et_webview_url"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn_load_webview"
        android:text="加载内容"/>


</LinearLayout>
package mydemo.mycom.demo2;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class WebViw extends ActionBarActivity implements View.OnClickListener {


    private WebView wv;
    private EditText et_webview_url;
    private Button btn_load_webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_viw);

        wv = (WebView)findViewById(R.id.wv);
        et_webview_url = (EditText)findViewById(R.id.et_webview_url);
        btn_load_webview = (Button)findViewById(R.id.btn_load_webview);
        btn_load_webview.setOnClickListener(this);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_web_viw, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View view) {
        String path = et_webview_url.getText().toString().trim();
        if(TextUtils.isEmpty(path))
        {
            Toast.makeText(this,"webview路径不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        wv.loadUrl(path);

    }
}

 

android webview

标签:

原文地址:http://www.cnblogs.com/zoro-zero/p/4524670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!