【问题标题】:EditText with type numberDecimal doesn't allow values starting with 0类型为 numberDecimal 的 EditText 不允许以 0 开头的值
【发布时间】:2018-05-24 08:33:46
【问题描述】:

我有一个带有 inputType numberDecimal 的 EditText,所以它应该允许插入十进制值,例如 4.2、3.14 等。但它不允许我插入

如何允许用户写入任何大于或等于 0.0 的数字?

在 Android 7.0.1 上测试

EditText XML:

<EditText
  android:id="@+id/editText"
  android:layout_width="match_parent"
  android:layout_height="match_parent" 
  android:maxEms="10"
  android:layout_gravity="center"   
  android:inputType="numberDecimal"
  android:textSize="16dp" 
  android:digits="0123456789." />

【问题讨论】:

    标签: java android


    【解决方案1】:

    以下似乎对我有用。

    <EditText
        android:id="@+id/buyET"
        android:layout_width="150dp"
        android:layout_height="45dp"
        android:ems="10"
        android:inputType="numberDecimal" />
    

    对你来说,它看起来像这样:

    <EditText
      android:id="@+id/editText"
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
      android:ems="10"
      android:layout_gravity="center"   
      android:inputType="numberDecimal"
      android:textSize="16dp"  />
    

    【讨论】:

    • 好的,我知道为什么它不起作用了。我的代码中有输入过滤器,只允许最大。小数点之前和之后的数字,这就是它的原因。我现在真的很蹩脚,很抱歉浪费你的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    相关资源
    最近更新 更多