繁体   English   中英

Android国家/地区代码选择器库

[英]Android Country code selector lib

目前,我正在使用https://github.com/hbb20/CountryCodePickerProject库,以允许用户选择国家/地区,格式化输入的电话号码并验证号码。

它很好,但不能满足我的要求。 有几个问题。

  1. 如果用户输入电话号码。 带有国家/地区代码的电话,则视为无效电话号码。

即选择印度,然后用户输入91 99 xxx xxxxx。(无效)。

  1. 输入电话号码时 国家代码,国旗或国家/地区无法选择。
  2. 格式也不适用于变化的国家。
  3. 如果用户编辑电话号码。 已保存,然后保存其附加的国家/地区代码。

即,如果我要更改91 99 xxx xxxxx,则将其另存为91 91 99 xxx xxxxx。 哪个无效。

谁能为我推荐解决方案或Android的智能库。

试试这个库,它比HBB20更好

将jitpack.io添加到您的根build.gradle文件中:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

将库添加到您的应用程序build.gradle文件中,然后进行同步

dependencies {
    compile 'com.github.joielechong:countrycodepicker:2.1.5'
}

将ccp视图添加到xml布局

<com.rilixtech.CountryCodePicker
      android:id="@+id/ccp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />

将AppCompatEditText视图添加到布局

<android.support.v7.widget.AppCompatEditText
       android:id="@+id/phone_number_edt"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="phone"
       android:inputType="phone"/>

使用代码注册AppCompatEditText

CountryCodePicker ccp;
AppCompatEditText edtPhoneNumber;

ccp = (CountryCodePicker) findViewById(R.id.ccp);
edtPhoneNumber = (AppCompatEditText) findViewById(R.id.phone_number_edt);

ccp.registerPhoneNumberTextView(edtPhoneNumber);

您可以使用isValid()方法检查电话号码的有效性。

希望这可以帮助。 有关更多信息,请检查此链接:

https://github.com/joielechong/CountryCodePicker

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM