android webview

<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);

    }
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。