Android App Mein Country Code Picker Library Kaise Add Karein? // How to add Country Code Picker in Android
Agar aap apni Android application mein mobile number input ke saath country code picker ka option dena chahte hain, toh aapko ek Country Code Picker (CCP) library ka use karna chahiye. Yeh feature WhatsApp, Truecaller jaise apps mein bhi diya gaya hota hai jahan user country code ke saath apna number select karta hai.
Is blog mein hum jaanenge ki Android project mein CCP library ko kaise integrate karein step-by-step.
Step 1: Gradle Dependency Add Karein
Sabse pehle aapko apne Android project ke
build.gradle (Module: app) file mein dependency add karni hogi.dependencies {
implementation 'com.hbb20:ccp:2.7.3'
}
Step 2: XML Layout Mein CountryCodePicker Add Karein
Apne XML layout file (e.g.
activity_main.xml) mein neeche diya gaya component add karein:<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etPhoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone number"
android:inputType="phone" />
</LinearLayout>
Step 4: Java Code Mein Integration
CountryCodePicker ccp;
EditText etPhoneNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ccp = findViewById(R.id.ccp);
etPhoneNumber = findViewById(R.id.etPhoneNumber);
ccp.registerCarrierNumberEditText(etPhoneNumber);
// Full number ke liye
String fullNumber = ccp.getFullNumberWithPlus();
Toast.makeText(this, "Number: " + fullNumber, Toast.LENGTH_SHORT).show();
}
Extra Features (Optional)
-
Aap flags disable/enable kar sakte hain.
-
Country search dialog ko customize kar sakte hain.
-
Number validation bhi possible hai.
Aap flags disable/enable kar sakte hain.
Country search dialog ko customize kar sakte hain.
Number validation bhi possible hai.
Conclusion
Country Code Picker library Android app mein international phone number input ko easy aur user-friendly bana deti hai. Is library ka integration simple hai aur user experience mein bhi enhancement lata hai. Agar aap kisi registration ya login form mein mobile number le rahe hain, toh CCP ek perfect choice hai.
Comments
Post a Comment