MaxLength属性在Android中无法正常工作

问题描述 投票:0回答:1

我在xml中使用EditText,我希望用户输入他们的电话号码。我想限制位数(应为10位),所以我应用了maxLength="10"。除我以“ 0”开头的数字外,所有情况都可以正常使用,它使我可以写9位数字。以下是我为EditText附加的代码。

<EditText
                    android:textSize="16sp"
                    android:singleLine="true"
                    android:id="@+id/phone"
                    android:textColor="#7c6596"
                    android:textColorHint="#cab2e5"
                    android:background="@drawable/border_radius"
                    android:gravity="center"
                    android:layout_margin="1dp"
                    android:padding="10dp"
                    android:inputType="number"
                    android:maxLength="10"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Phone number"/>
android xml
1个回答
0
投票

所以这是解决方案。我在xml中应用maxLength,与此同时,我的类文件中的该字段上也有一个TextWatcher。我删除了TextWatcher,现在所有情况都得到了很好的处理。希望它可以帮助某人。干杯!

© www.soinside.com 2019 - 2024. All rights reserved.