Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中限制输入数字的长度?_Android_Android Layout_Android Fragments - Fatal编程技术网

如何在Android中限制输入数字的长度?

如何在Android中限制输入数字的长度?,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我开发了一个应用程序,要求用户输入ID和电话号码。使用Android,我想限制输入号码的位数。我的类型编号框。使用android:maxLength作为您的EditText 例如: <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:ma

我开发了一个应用程序,要求用户输入ID和电话号码。使用Android,我想限制输入号码的位数。我的类型编号框。

使用
android:maxLength
作为您的
EditText

例如:

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLength="12"/>

编辑文本中使用
android:maxLength
作为属性

例如:

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLength="12"/>


您是否只支持来自一个国家/地区的电话号码?通常,对于这类事情,您希望使其健壮,以便它适用于所有国家及其特定的电话号码格式。在过去,我使用谷歌的libphonenumber(见此处:)和PhoneNumber FormattingTestWatcher:谢谢你提供这些链接,它们真的帮了我很多忙。你只支持一个国家的电话号码吗?通常,对于这类事情,您希望使其健壮,以便它适用于所有国家及其特定的电话号码格式。过去我用过谷歌的libphonenumber(见这里:)和PhoneNumber FormattingTestWatcher:谢谢你提供的这些链接,它们真的帮了我很大的忙