Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetScrollBarStyle, setOnKeyListener

0
	@SuppressLint({ "SetJavaScriptEnabled" }) 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reader);
		this.initWebView();
		webView.loadUrl("file:///android_asset/" + book.bookLocation
				+ "/OPS/chapter5.html"); 
	} 
 
	@SuppressWarnings("deprecation") 
	@SuppressLint({ "SetJavaScriptEnabled" }) 
	private void initWebView() { 
		// �Ӳ����ļ�����չwebView 
		this.webView = (WebView) this.findViewById(R.id.webView);
		webView.getSettings().setJavaScriptEnabled(true);// ����JS
		webView.setScrollBarStyle(0);// ������������Ϊ0���Dz������������ռ䣬�����񸲸�����ҳ��
		settings = webView.getSettings();
		settings.setSupportZoom(true);
		if (settings.getTextSize() == WebSettings.TextSize.SMALLEST) {
			fontSize = 1;
		} else if (settings.getTextSize() == WebSettings.TextSize.SMALLER) {
			fontSize = 2;
		} else if (settings.getTextSize() == WebSettings.TextSize.NORMAL) {
			fontSize = 3;
		} else if (settings.getTextSize() == WebSettings.TextSize.LARGER) {
			fontSize = 4;
		} else if (settings.getTextSize() == WebSettings.TextSize.LARGEST) {
			fontSize = 5;
		} 
		// ����Ĭ�Ϻ��˰�ť�����ã��滻��WebView���IJ鿴��ʷҳ�� 
		webView.setOnKeyListener(new View.OnKeyListener() {
			@Override 
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event.getAction() == KeyEvent.ACTION_DOWN) {
					if ((keyCode == KeyEvent.KEYCODE_BACK)
							&& webView.canGoBack()) {
Stop searching for code, let great code find you!  Add Codota to your java IDE