问题描述
是否可以禁用文本选择以使 PhoneGap 应用更类似于普通的原生应用?
Is it possible to disable text selection to make a PhoneGap app more similar to normal native app?
像这样:
document.onselectstart = function() {return false;}
或:
* {
user-select: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
或者许多其他事情不起作用.
Or many other things don't work.
推荐答案
我四处寻找这方面的帮助.这终于对我有用了.
I looked all over for help on this. This finally worked for me.
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
super.appView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
return true;
}
});
}
}
setOnClickListener 有什么神奇之处.确保在调用 super.loadUrl 之后放置它.
The setOnClickListener is what does the magic. Make sure you put this AFTER your call to super.loadUrl.
当然,这将禁用整个应用程序的文本选择,但我对此表示同意,目前我没有其他办法.
Of course, this will disable text selection for your entire app, but I'm OK with that, and I don't have any other way around it for now.
我还不确定这的完整含义,但我确实使用了 JqueryMobile 事件taphold",它仍然可以正常工作.我相信这是通过处理 appView(托管您的 HTML 应用程序)上的长按并防止它冒泡来实现的.
I'm not sure of the complete implications of this yet, but I do make use of the JqueryMobile event "taphold", and it still works fine. I believe this works by handling the long click on the appView (which hosts your HTML app) and preventing it from bubbling up.
这篇关于在 PhoneGap 中禁用文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!