|
@@ -11,8 +11,8 @@ import android.view.WindowManager; |
|
@@ -11,8 +11,8 @@ import android.view.WindowManager; |
|
11
|
import android.webkit.WebSettings;
|
11
|
import android.webkit.WebSettings;
|
|
12
|
import android.webkit.WebView;
|
12
|
import android.webkit.WebView;
|
|
13
|
import android.widget.LinearLayout;
|
13
|
import android.widget.LinearLayout;
|
|
|
|
14
|
+import android.widget.Toast;
|
|
14
|
|
15
|
|
|
15
|
-import com.qiwan.gameboxh5.R;
|
|
|
|
16
|
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
16
|
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
|
17
|
|
17
|
|
|
18
|
public class MainActivity extends Activity {
|
18
|
public class MainActivity extends Activity {
|
|
@@ -51,38 +51,32 @@ public class MainActivity extends Activity { |
|
@@ -51,38 +51,32 @@ public class MainActivity extends Activity { |
|
51
|
|
51
|
|
|
52
|
private void initView() {
|
52
|
private void initView() {
|
|
53
|
mLlRoot = findViewById(R.id.ll_root);
|
53
|
mLlRoot = findViewById(R.id.ll_root);
|
|
54
|
- mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, 0);
|
54
|
+ mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, mTintManager.getConfig().getNavigationBarHeight()+20);
|
|
55
|
mWebView = findViewById(R.id.webview);
|
55
|
mWebView = findViewById(R.id.webview);
|
|
56
|
}
|
56
|
}
|
|
57
|
|
57
|
|
|
58
|
private void initWebView() {
|
58
|
private void initWebView() {
|
|
59
|
- mWebView.requestFocusFromTouch();// 设置可以获得焦点
|
|
|
|
60
|
- mWebView.setBackgroundColor(Color.argb(0, 0, 0, 0));
|
|
|
|
61
|
- mWebView.requestFocus(View.FOCUS_DOWN);// 获取焦点 或者使用 webView.requestFocus()同样的效果
|
|
|
|
62
|
- mWebView.setEnabled(true); // 这里如果设置false, 则点击h5页面中的输入框时不能唤起软键盘
|
|
|
|
63
|
- mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
64
|
- mWebView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
65
|
- @Override
|
|
|
|
66
|
- public boolean onLongClick(View v) {
|
|
|
|
67
|
- return true;
|
|
|
|
68
|
- }
|
|
|
|
69
|
- });
|
|
|
|
70
|
-
|
|
|
|
71
|
WebSettings webSettings = mWebView.getSettings();
|
59
|
WebSettings webSettings = mWebView.getSettings();
|
|
72
|
- webSettings.setDefaultTextEncodingName("utf-8");
|
|
|
|
73
|
webSettings.setJavaScriptEnabled(true);
|
60
|
webSettings.setJavaScriptEnabled(true);
|
|
74
|
- webSettings.setTextZoom(100);
|
|
|
|
75
|
- webSettings.setDomStorageEnabled(true);
|
|
|
|
76
|
- webSettings.setUseWideViewPort(true);
|
|
|
|
77
|
- webSettings.setLoadWithOverviewMode(true);
|
|
|
|
78
|
- webSettings.setSupportZoom(true);
|
|
|
|
79
|
webSettings.setBuiltInZoomControls(true);
|
61
|
webSettings.setBuiltInZoomControls(true);
|
|
80
|
- // 解决部分机子不设置出现存储不了数据问题
|
62
|
+ webSettings.setDisplayZoomControls(false);
|
|
81
|
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
63
|
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
|
82
|
- webSettings.setDatabaseEnabled(true);
|
|
|
|
83
|
- String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
|
|
|
84
|
- webSettings.setDatabasePath(dir);
|
|
|
|
85
|
- webSettings.setGeolocationEnabled(true);
|
64
|
+ webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
86
|
webSettings.setAllowFileAccess(true);
|
65
|
webSettings.setAllowFileAccess(true);
|
|
87
|
}
|
66
|
}
|
|
|
|
67
|
+
|
|
|
|
68
|
+ private long mBackPressedTime = 0;
|
|
|
|
69
|
+ @Override
|
|
|
|
70
|
+ public void onBackPressed() {
|
|
|
|
71
|
+ if (mWebView != null && mWebView.canGoBack()) {
|
|
|
|
72
|
+ mWebView.goBack();
|
|
|
|
73
|
+ } else {
|
|
|
|
74
|
+ if(System.currentTimeMillis() - mBackPressedTime > 2000) {
|
|
|
|
75
|
+ Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show();
|
|
|
|
76
|
+ mBackPressedTime = System.currentTimeMillis();
|
|
|
|
77
|
+ } else {
|
|
|
|
78
|
+ super.onBackPressed();
|
|
|
|
79
|
+ }
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+ }
|
|
88
|
} |
82
|
} |