本文仅仅记录一下做过的一个项目3DBGame中的代码,详细WebView用法,请参考此文:
《Android:WebView用法(Js交互)》
package fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.myapplication.dbgame.R;
/**
* A simple {@link Fragment} subclass.
*/
public class ForumFragment extends Fragment {
private String url = "http://bbs.3dmgame.com/forum.php";
private WebView webView;
public ForumFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_forum, container, false);
webView = (WebView) view.findViewById(R.id.wv_forum);
webView.getSettings().setJavaScriptEnabled(true);
//支持缩放按钮
webView.getSettings().setSupportZoom(true);
//隐藏缩放按钮
webView.getSettings().setBuiltInZoomControls(true);
//web1就是你自己定义的窗口对象。
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
return view;
}
}