英文:
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.
答案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
}
})
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论