Does android have a numeric keypad?

前端 未结 5 708
挽巷
挽巷 2020-12-09 18:49

Is there a way in android to invoke a numeric only keypad, i.e. a virtual keypad that contains only the numbers 0 to 9 and a \".\" sign?

相关标签:
5条回答
  • 2020-12-09 19:11

    Basically, you need what Peter Boughton said.

    More generally, if you need to invoke different type of keyboard, depending on the input you expect on your EditText component, you should use the IMF (Input Media Framework) and different IMEs (Input Media Editors).

    You can customize not only the input symbols, but also the layout of the keyboard in your application, auto-completion and other options.

    You may want to read this post in the Android Developers Blog: Updating Applications for On-screen Input Methods

    0 讨论(0)
  • 2020-12-09 19:18

    Make sure you only have: <EditText android:numeric="decimal" />

    and not both: <EditText android:numeric="decimal" android:digits="0123456789." />

    The latter, ie using both numeric and digits was not working for me. However, using only numeric works.

    0 讨论(0)
  • 2020-12-09 19:19

    If you're talking about restricting input to 0-9 + "." for an EditText box, I use the android:numeric="decimal" attribute in the layout XML.

    <EditText android:numeric="decimal" />
    

    If you're working with dynamically generated EditText views, the relevant method to call on it is setKeyListener()

    0 讨论(0)
  • 2020-12-09 19:25

    Try doing android:inputType="phone" ?

    0 讨论(0)
  • 2020-12-09 19:29
    <EditText android:numeric="decimal" />
    

    only does not affect keypad to convert into decimal. Instead, use:

      <EditText android:inputType="phone" android:numeric="decimal"></EditText>
    

    This will show the numeric keypad only.

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