Disabling text selection in PhoneGap

后端 未结 9 697
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 14:14

Is it possible to disable text selection to make a PhoneGap app more similar to normal native app?

Something like this:



        
相关标签:
9条回答
  • 2020-12-02 15:17

    Recently updated to Android 4.4 kitkat and it resolved the problem of Edittext showing up on taphold (long press). Apparently edittext doesn't showup on taphold with jquery mobile and phonegap on android 4.4. I am using a custom aosp rom so haven't tested on an official release but am guessing (and hoping) it should work as well for any 4.4 release. It also seems to resolved other conflicts I was having with onclick which I posted below.

    Older method I found that works (with possible issues) for older ICS roms (only tested on 4.0.4 custom rom).
    By adding a scrollbar

    example:

    <div id="scroll">content</div> 
    
    <style>
    #scroll {
    
    height: 100%;
    width: 100%;
    }
    </style>
    

    It disables the EditText from popping on taphold (long press) for phonegap and jquery mobile as well. Not sure yet if this will cause any conflicts (as seems to have some effects with onclick which am looking at sorting out) but with regular text should work well.--- Issues sorted out with Android 4.4 and no need for scroll either anymore. (see top of post)

    0 讨论(0)
  • 2020-12-02 15:18

    For me this was the best:

    -webkit-tap-highlight-color: rgba(0,0,0,0); 
    tap-highlight-color: rgba(0,0,0,0);
    

    My case happened with pixi.js, with

    plugins.interaction.autoPreventDefault = true;
    
    0 讨论(0)
  • 2020-12-02 15:20

    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;
                }
            });
        }
    }
    

    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.

    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.

    0 讨论(0)
提交回复
热议问题