hbb20 / CountryCodePickerProject

Country Code Picker (CCP) is an android library which provides an easy way to search and select country or international phone code. Also supports Android EditText phone mask and international phone validation.
Apache License 2.0
1.52k stars 506 forks source link

Custom Dialog - Overwrite XML #265

Closed tamimattafi closed 5 years ago

tamimattafi commented 6 years ago

Hello ! First of all, thank you so much for this beautiful library! it's really classy and time saving i have question on how can i customize the picker Dialog.. i have a main theme for my application so, i have to edit the dialog design to make it suits the whole design, but the available XML attributes are not enough is there anyway to be able to edit things like :

hbb20 commented 5 years ago

There are two ways you can try.

  1. Attach your custom "DialogEventsListener". On the callback of onCcpDialogOpen, instance of Dialog will be returned. Fetch views from this dialog and customize them programatically.
  2. Download XML file of dialog from github. Then add that file to your project's layout folder. Don't change the file name. Modify layout components as per your requirement. Don't remove any component with ID as CCP will fetch components by id on run time. Removal of component will result in NPE

If this is not sufficient, comment back with details. Thanks.

wesetiawan commented 5 years ago

i got some tutorial but i dont know how to implement this . Can you teach me ? https://www.youtube.com/watch?v=MgJcVKvWYoc&t=193s

mohamedagamy commented 4 years ago

I have made this extension function On CountryCodePicker Object in kotlin also I copied the following file for dialog layout and recyclerview layout only in my project layout_picker_dialog.xml layout_recycler_country_tile.xml also I used the custom decorator from another library MyDividerItemDecoration

fun CountryCodePicker.customizeDialog(context: Context){
    this.setDialogEventsListener(object : CountryCodePicker.DialogEventsListener {
        override fun onCcpDialogDismiss(dialogInterface: DialogInterface?) {
            dialogInterface?.cancel()
        }
        override fun onCcpDialogCancel(dialogInterface: DialogInterface?) {
            dialogInterface?.cancel()
        }
        override fun onCcpDialogOpen(dialog: Dialog?) {
            val window = dialog?.window
            //window?.setContentView(R.layout.layout_picker_dialog)
            window?.setLayout(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT)

            val dividerDrawable = ContextCompat.getDrawable(context, R.drawable.divider_line)
            val recyclerViewCountry = dialog?.window?.decorView?.recycler_countryDialog
            recyclerViewCountry?.addItemDecoration(MyDividerItemDecoration(dividerDrawable))
            recyclerViewCountry?.adapter?.notifyDataSetChanged()
        }
    })
}

I need something like that to be added to the library.