如何更改CountryCodePicker(CCP)的对话框:

huangapple go评论87阅读模式
英文:

How to change dialog of CountryCodePicker (CCP)

问题

如何将CountryCodePicker(CCP)对话框标题从“Select a Country”更改为“Select a country or region”。我正在使用CCP库进行国家选择。如下图片所示,对话框标题为“Select a country”。

英文:

How can i change dialog of CountryCodePicker (CCP) title from Select a Country to Select a country or region. im using CCP library for Country Selector. As you can see the below picture dialog title is Select a country.

如何更改CountryCodePicker(CCP)的对话框:

答案1

得分: 2

很简单当对话框打开时你可以检查并获取标题的文本视图然后通过编程方式修改其文本就像这样

    CountryCodePicker cpp;
    cpp = (CountryCodePicker) findViewById(R.id.yourid);

    cpp.setDialogEventsListener(new CountryCodePicker.DialogEventsListener() {
        @Override
        public void onCcpDialogOpen(Dialog dialog) {
            // 你的代码
            TextView title = (TextView) dialog.findViewById(R.id.textView_title);
            title.setText("选择国家或地区");
        }

        @Override
        public void onCcpDialogDismiss(DialogInterface dialogInterface) {
            // 你的代码
        }

        @Override
        public void onCcpDialogCancel(DialogInterface dialogInterface) {
            // 你的代码
        }
    });
英文:

Well very simple, you check when the dialog is opened , get the title textview and change its text programmatically just like this:

CountryCodePicker cpp;
cpp=(CountryCodePicker) findViewById(R.id.yourid);


cpp.setDialogEventsListener(new CountryCodePicker.DialogEventsListener() {
            @Override
            public void onCcpDialogOpen(Dialog dialog) {
                //your code
              TextView title =(TextView)  dialog.findViewById(R.id.textView_title);
              title.setText("Select Country or Region");
            }

            @Override
            public void onCcpDialogDismiss(DialogInterface dialogInterface) {
                //your code
            }

            @Override
            public void onCcpDialogCancel(DialogInterface dialogInterface) {
                //your code
            }
        });

答案2

得分: 1

binding.ccpPhone.setDialogEventsListener(object : DialogEventsListener {
    override fun onCcpDialogOpen(dialog: Dialog) {
        //your code
        dialog.findViewById<TextView>(R.id.textView_title).text = "Title Here"
        /*dialog.findViewById<CardView>(R.id.cardViewRoot).background = resources.getDrawable(R.drawable.bg_white_bottom_sheet, null)
        //dialog size

        val width = (resources.displayMetrics.widthPixels * 0.85).toInt()
        val height = (resources.displayMetrics.heightPixels * 0.85).toInt()
        dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, height)
        dialog.window?.setGravity(Gravity.BOTTOM)*/
    }

    override fun onCcpDialogDismiss(dialogInterface: DialogInterface) {
        //your code
    }

    override fun onCcpDialogCancel(dialogInterface: DialogInterface) {
        //your code
    }
})

如何更改CountryCodePicker(CCP)的对话框:


<details>
<summary>英文:</summary>

For Kotlin

binding.ccpPhone.setDialogEventsListener(object : DialogEventsListener {
override fun onCcpDialogOpen(dialog: Dialog) {
//your code
dialog.findViewById<TextView>(R.id.textView_title).text = "Title Here"
/*dialog.findViewById<CardView>(R.id.cardViewRoot).background = resources.getDrawable(R.drawable.bg_white_bottom_sheet, null)
//dialog size

            val width = (resources.displayMetrics.widthPixels * 0.85).toInt()
            val height = (resources.displayMetrics.heightPixels * 0.85).toInt()
            dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, height)
            dialog.window?.setGravity(Gravity.BOTTOM)*/
        }

        override fun onCcpDialogDismiss(dialogInterface: DialogInterface) {
            //your code
        }

        override fun onCcpDialogCancel(dialogInterface: DialogInterface) {
            //your code
        }
    })
[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/5IIJs.jpg

</details>



huangapple
  • 本文由 发表于 2020年8月19日 19:31:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63486057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定