Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

cordova - PhoneGap for Android does not accept the 9 key

I have a strange problem in my PhoneGap-based android app. On certain screens, the number 9 key is completely ignored. This happens on all my Android 2.X devices. I have tried with previous versions of PG and found that the problem first occurred in v1.2.

Here is the code to a sample index.html file that should reproduce the issue. On both Android 2.2 and 2.3, the text boxes labeled as "broken" do not accept the number 9 as input.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Test</title>
        <style>
        body
        {
            margin:0;
            padding:0;
            font-size:20px;
        }

        input
        {
            height:20px;
        }

        #container_second
        {
            overflow:hidden;
            position:relative;
            width:100%;
            height:150px;
        }

        #container_second div
        {
            left: -2000px;
            position: absolute;
            -webkit-transform: matrix(1, 0, 0, 1, 2000, 0);
        }
        </style>
    </head>
    <body>
        <br />
        <div id="container_first">
            <div>
                Working Text: <br /><input type="text" /><br /><br />
                Working Tel: <br /><input type="tel" />
            </div>
        </div>

        <br /><br />

        <div id="container_second">
            <div>
                Broken Text: <br /><input type="text" /><br /><br />
                Broken Tel: <br /><input type="tel" />
            </div>
        </div>
    </body>
    </html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It might be related to this issue. For some reason PhoneGap is calling setNavDump on the web view's WebSettings. setNavDump is an obsolete method according to the android docs so you should be fine if you disable it.

One way to do it is by overriding the init method in your class that extends DroidGap

    @Override
public void init() {
    super.init();       
    this.appView.getSettings().setNavDump(false);
}

If that doesn't work, try adding it after the loadUrl call in the existing onCreate method:

@Override
public void onCreate(Bundle savedInstanceState) {
    //... snip ...
    super.loadUrl("file:///android_asset/www/index.html", 12000);
    this.appView.getSettings().setNavDump(false);
    //... snip ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...