Last active
January 19, 2016 08:09
-
-
Save a1yama/3637f8e75b11c81d1b5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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