Skip to content

Instantly share code, notes, and snippets.

@a1yama a1yama/MainActivity.java
Last active Jan 19, 2016

Embed
What would you like to do?
package jp.hoge.webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://hoge.jp/");
webView.getSettings().setJavaScriptEnabled(true);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
// 端末の戻るボタンでブラウザバック
if(keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.