【问题标题】:Android keyboard input typeAndroid键盘输入类型
【发布时间】:2013-11-29 22:07:25
【问题描述】:

我正在我的 webview 中显示 android 软键盘,如下所示:

InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
manager.showSoftInput(myWebview, InputMethodManager.SHOW_IMPLICIT);

有没有办法指定输入类型,例如只显示数字?

请注意,我没有使用任何 EditText,所以我无法在我的视图中设置它。想知道这是否可能?

【问题讨论】:

    标签: android android-webview


    【解决方案1】:

    在您的 HTML 中使用 <input type=number>。根据QuirksMode 的说法,至少Android 2.3 主要支持(有一些小错误)。要测试这是否是您想要的行为,请使用 this test page

    【讨论】:

      【解决方案2】:

      我假设您希望根据 WebView 的输入来更改键盘输入类型,如果是这样,这是最好的选择。

      设置输入字段的类型来改变显示的键盘类型,如下:

      http://jsbin.com/eCeJAFaV/4/edit

      <!DOCTYPE html>
      <html>
      <head>
      <meta charset=utf-8 />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>JS Bin</title>
      </head>
      <body>
          <p><input type="color" name="color" placeholder="color" /></p>
          <p><input type="date" name="date" placeholder="date" /></p>
          <p><input type="datetime" name="datetime" placeholder="datetime" /></p>
          <p><input type="email" name="email" placeholder="email" /></p>
          <p><input type="month" name="month" placeholder="month" /></p>
          <p><input type="number" name="number" placeholder="number" /></p>
          <p><input type="search" name="search" placeholder="search" /></p>
          <p><input type="tel" name="tel" placeholder="tel" /></p>
          <p><input type="time" name="time" placeholder="time" /></p>
          <p><input type="url" name="url" placeholder="url" /></p>
            <p><input type="week" name="week" placeholder="week" /></p>
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 2018-03-28
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 2018-12-03
        • 1970-01-01
        • 1970-01-01
        • 2014-12-23
        • 2011-09-20
        相关资源
        最近更新 更多