|
...
|
...
|
@@ -11,8 +11,8 @@ import android.view.WindowManager; |
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.qiwan.gameboxh5.R;
|
|
|
|
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
|
|
|
|
|
|
|
public class MainActivity extends Activity {
|
|
...
|
...
|
@@ -51,38 +51,32 @@ public class MainActivity extends Activity { |
|
|
|
|
|
|
|
private void initView() {
|
|
|
|
mLlRoot = findViewById(R.id.ll_root);
|
|
|
|
mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, 0);
|
|
|
|
mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, mTintManager.getConfig().getNavigationBarHeight()+20);
|
|
|
|
mWebView = findViewById(R.id.webview);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initWebView() {
|
|
|
|
mWebView.requestFocusFromTouch();// 设置可以获得焦点
|
|
|
|
mWebView.setBackgroundColor(Color.argb(0, 0, 0, 0));
|
|
|
|
mWebView.requestFocus(View.FOCUS_DOWN);// 获取焦点 或者使用 webView.requestFocus()同样的效果
|
|
|
|
mWebView.setEnabled(true); // 这里如果设置false, 则点击h5页面中的输入框时不能唤起软键盘
|
|
|
|
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
mWebView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
WebSettings webSettings = mWebView.getSettings();
|
|
|
|
webSettings.setDefaultTextEncodingName("utf-8");
|
|
|
|
webSettings.setJavaScriptEnabled(true);
|
|
|
|
webSettings.setTextZoom(100);
|
|
|
|
webSettings.setDomStorageEnabled(true);
|
|
|
|
webSettings.setUseWideViewPort(true);
|
|
|
|
webSettings.setLoadWithOverviewMode(true);
|
|
|
|
webSettings.setSupportZoom(true);
|
|
|
|
webSettings.setBuiltInZoomControls(true);
|
|
|
|
// 解决部分机子不设置出现存储不了数据问题
|
|
|
|
webSettings.setDisplayZoomControls(false);
|
|
|
|
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
|
|
|
webSettings.setDatabaseEnabled(true);
|
|
|
|
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
|
|
|
webSettings.setDatabasePath(dir);
|
|
|
|
webSettings.setGeolocationEnabled(true);
|
|
|
|
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
|
|
webSettings.setAllowFileAccess(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private long mBackPressedTime = 0;
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (mWebView != null && mWebView.canGoBack()) {
|
|
|
|
mWebView.goBack();
|
|
|
|
} else {
|
|
|
|
if(System.currentTimeMillis() - mBackPressedTime > 2000) {
|
|
|
|
Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show();
|
|
|
|
mBackPressedTime = System.currentTimeMillis();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|