禁用所有页面长按功能

This commit is contained in:
FinleyHsu
2026-07-28 16:58:26 +08:00
parent eab3ca651a
commit 839edd1e4a
3 changed files with 30 additions and 1 deletions
@@ -43,6 +43,9 @@ public class MainActivity extends Activity {
webView.setBackgroundColor(Color.rgb(248, 250, 248));
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
// 工业终端只响应点击操作,禁止长按选择文字、弹出菜单及震动反馈。
webView.setLongClickable(false);
webView.setHapticFeedbackEnabled(false);
// 开启应用运行、接口访问和本地配置所需的 WebView 能力。
WebSettings settings = webView.getSettings();
+8 -1
View File
@@ -11,9 +11,16 @@
--cream: #f2f4ee;
}
* { box-sizing: border-box; }
* {
box-sizing: border-box;
/* 禁止所有页面长按选择文字及弹出系统复制菜单。 */
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
}
html { background: #dfe8e2; }
body { margin: 0; color: var(--ink); font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif; }
img, a { -webkit-user-drag: none; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
+19
View File
@@ -51,3 +51,22 @@ test("正式代码不包含历史人员、机台或重量模拟数据", async ()
assert.match(page, /evaluateStability\(stableSamples\.current\)/);
assert.match(utilities, /返回值统一为千克/);
});
test("网页和 Android 原生层均禁用长按功能", async () => {
const [css, androidActivity] = await Promise.all([
readFile(new URL("../app/globals.css", import.meta.url), "utf8"),
readFile(
new URL(
"../android-app/android/app/src/main/java/com/woer/smartscale/MainActivity.java",
import.meta.url,
),
"utf8",
),
]);
assert.match(css, /-webkit-touch-callout:\s*none/);
assert.match(css, /-webkit-user-select:\s*none/);
assert.match(css, /user-select:\s*none/);
assert.match(androidActivity, /webView\.setLongClickable\(false\)/);
assert.match(androidActivity, /webView\.setHapticFeedbackEnabled\(false\)/);
});