【问题标题】:Configure android EditText to allow decimals and negatives配置 android EditText 以允许小数和负数
【发布时间】:2011-11-24 12:32:46
【问题描述】:

我有一个 Android EditText,我想让数字键盘出现。

如果我将 android:inputType 设置为 numberSigned,我将获得数字键盘和输入负数的能力。但是,这不会让我使用小数。如果我使用 numberDecimal inputType,我可以使用小数,但不能使用负数。

如何获得能够输入小数和负数的数字键盘?

【问题讨论】:

    标签: android android-edittext decimal


    【解决方案1】:

    你只是在你的 EditText 中错过了这个,

    android:inputType="numberDecimal|numberSigned"
    

    【讨论】:

    • 尽管这目前的投票率最高,但它仍然对我不起作用。 hrrh
    【解决方案2】:

    查看此链接可能对您有所帮助 http://developer.android.com/resources/articles/creating-input-method.html

    android:inputtype 的可能值为:

    •none
    •text
    •textCapCharacters
    •textCapWords
    •textCapSentences
    •textAutoCorrect
    •textAutoComplete
    •textMultiLine
    •textImeMultiLine
    •textNoSuggestions
    •textUri
    •textEmailAddress
    •textEmailSubject
    •textShortMessage
    •textLongMessage
    •textPersonName
    •textPostalAddress
    •textPassword
    •textVisiblePassword
    •textWebEditText
    •textFilter
    •textPhonetic
    •textWebEmailAddress
    •textWebPassword
    •number
    •numberSigned
    •numberDecimal
    •numberPassword
    •phone
    •datetime
    •date
    •time
    

    【讨论】:

      【解决方案3】:

      我们可以使用,

      edit_text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
      

      如果我们需要以编程方式使用..

      【讨论】:

        【解决方案4】:

        有些手机在同一个按钮上有小数点和负数,所以不能做负数。我想出了一种方法,您可以通过简单地添加来分隔按钮-

        android:inputType="numberDecimal|numberSigned|textPersonName"
        

        android:digits="0123456789-."

        这样你仍然有数字键盘布局,但负数和小数点按钮将是分开的,你不能使用任何其他数字来搞乱应用程序。

        【讨论】:

          【解决方案5】:

          这以编程方式对我有用。下面是代码:

          editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
          

          【讨论】:

            【解决方案6】:

            经过测试,解决办法是

            inputET.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
            
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2021-07-30
              • 2014-02-15
              • 1970-01-01
              • 1970-01-01
              • 2019-04-23
              • 2022-01-22
              • 1970-01-01
              相关资源
              最近更新 更多