MainActivity.java
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.qiwan.gamebox;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import com.qiwan.gameboxh5.R;
import com.readystatesoftware.systembartint.SystemBarTintManager;
public class MainActivity extends Activity {
private LinearLayout mLlRoot;
private WebView mWebView;
private SystemBarTintManager mTintManager;
private String mUrl = "https://cdn.kky.cn/yxhz/index.html#/home";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTintManager = new SystemBarTintManager(this);
mTintManager.setStatusBarTintEnabled(false);
mTintManager.setNavigationBarTintEnabled(true);
mTintManager.setStatusBarTintColor(Color.parseColor("#FFFFFF"));
//适配异形屏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
setContentView(R.layout.activity_main);
initView();
initWebView();
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey("AuthParams")) {
String parameterValue = extras.getString("AuthParams");
mUrl = mUrl + "?" + parameterValue;
}
}
mWebView.loadUrl(mUrl);
}
private void initView() {
mLlRoot = findViewById(R.id.ll_root);
mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, 0);
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.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setDatabaseEnabled(true);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
webSettings.setDatabasePath(dir);
webSettings.setGeolocationEnabled(true);
webSettings.setAllowFileAccess(true);
}
}