高学平的网络日志

  • 编程语言
    • PHP服务器脚本
    • Java编程语言
    • Python程序设计
  • 移动开发
    • Android开发
    • IOS开发
  • 架构运维
  • 数据库技术
  • 前端设计
  • 胡言乱语
  • AI
  • 关于我

android使用WebView示图

  • Blackford
  • 2014-05-03
  • 0

主程序
[java]
package com.example.mywebview;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

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

WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBlockNetworkImage(true);
wv.setWebViewClient(new CallBack());
wv.loadUrl("http://www.gaoxueping.com");
}

@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;
}

private class CallBack extends WebViewClient{

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
return (false);
}

}

}
[/java]
布局文件
[xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<WebView android:id="@+id/webview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
[/xml]
注意次app需要加入访问互联网的权限

© 2023 高学平的网络日志
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}