Android键盘输入类型

时间:2013-11-28 13:33:47

标签: android android-webview

我在我的网页视图中显示android软键盘,如下所示:

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

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

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

2 个答案:

答案 0 :(得分:0)

我假设您要根据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>

答案 1 :(得分:0)

在HTML中使用<input type=number>。根据{{​​3}},至少Android 2.3支持它(主要有一些小错误)。要测试这是否是您要使用的行为QuirksMode