如何设置的对话框按钮的文本字体大小字体大小、对话框、如何设置、按钮

2023-09-06 16:25:51 作者:穷水尽更词穷

我有一个Android应用程序,使用它从XML布局夸大一些自定义对话框。对话框的视图的内容来自于XML的布局,但实际的正面和负面的按钮调用建筑工地setPositiveButton和setNegativeButton方法添加,所以我无法控制(或至少不知道如何控制)造型的按钮中的自身

请参阅下面的onCreateDialog方法从我LoginConfirmationDialog.java文件延伸DialogFragment。基本上,它会弹出一个非常简单的对话了,要求确认谁是登录(即你是乔Schmoe?,有是和否按钮)。

在这种情况下,XML布局有只是一个单一的TextView,并且使这个容易(因为用户将建筑工人的大诺比肮脏的手指谁需要大量的文本和大按钮),我做的字体的TextView pretty的大。两个按钮,虽然有很多小字体的文字,因为他们不是我的布局的一部分,并加入与setPositiveButton和setNegativeButton方法,我怎么控制字体大小?

  @覆盖
公共对话onCreateDialog(包savedInstanceState){

    捆绑的args = this.getArguments();

    串empName = args.getString(empName);

    //使用生成器类简单的对话框建设
    AlertDialog.Builder建设者=新AlertDialog.Builder(getActivity());

    查看查看= getActivity()getLayoutInflater()膨胀(R.layout.dialog_login_confirmation,空)。

    TextView的消息=(TextView中)view.findViewById(R.id.txtLoginConfirmationMessage);
    message.setText(你+ empName +?);

    builder.setView(视图);

    builder.setPositiveButton(是,
            新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话框,INT ID){
                    mListener.onEmpConfirmPositiveClick(LoginConfirmationDialog.this);
                }
            });
    builder.setNegativeButton(否,
            新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话框,INT ID){
                    mListener.onEmpConfirmNegativeClick(LoginConfirmationDialog.this);
                }
            });

    //创建AlertDialog对象,并返回其
    返回builder.create();
}
 
vb 文本框编写程序,实现设置文本框内文本 字体 大小 颜色 的功能,要求用到框架 控件数组和单选按钮实

解决方案

而不是返回的 builder.create(),试试这个。 -

 最后AlertDialog警报= builder.create();
alert.setOnShowListener(新DialogInterface.OnShowListener(){
    @覆盖
    公共无效OnShow中(DialogInterface对话){
        按钮btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
        btnP​​ositive.setTextSize(TEXT_SIZE);

        按钮btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE);
        btnNegative.setTextSize(TEXT_SIZE);
    }
});

返回警报;
 

I have an android app that uses some custom dialogs which are inflated from XML layouts. The contents of the dialog's view come from the XML layout, but the actual positive and negative buttons are added by calling the builder's setPositiveButton and setNegativeButton methods, so I have no control over (or at least don't know how to control) the styling of the buttons themselves.

See the onCreateDialog method below from my LoginConfirmationDialog.java file which extends DialogFragment. It basically pops a very simple dialog up that asks for confirmation of who is logging in (i.e. "Are you Joe Schmoe?", with Yes and No buttons).

The XML layout in this case has just a single TextView, and to make this easy (because the users will be construction workers with big knobby dirty fingers who need large text and large buttons), I made the font for the TextView pretty big. The two buttons though have much smaller font for their text, and since they aren't part of my layout and are added with the setPositiveButton and setNegativeButton methods, how do I control the font size?

@Override    
public Dialog onCreateDialog(Bundle savedInstanceState) {

    Bundle args = this.getArguments();

    String empName = args.getString("empName");         

    // Use the Builder class for convenient dialog construction        
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_login_confirmation, null);

    TextView message = (TextView)view.findViewById(R.id.txtLoginConfirmationMessage);
    message.setText("Are you " + empName + "?");

    builder.setView(view);      

    builder.setPositiveButton("Yes", 
            new DialogInterface.OnClickListener() {                   
                public void onClick(DialogInterface dialog, int id) {
                    mListener.onEmpConfirmPositiveClick(LoginConfirmationDialog.this);
                }               
            });               
    builder.setNegativeButton("No", 
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    mListener.onEmpConfirmNegativeClick(LoginConfirmationDialog.this);
                }
            });  

    // Create the AlertDialog object and return it        
    return builder.create();    
}

解决方案

Instead of returning builder.create(), try this.-

final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        Button btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
        btnPositive.setTextSize(TEXT_SIZE);

        Button btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE);
        btnNegative.setTextSize(TEXT_SIZE);
    }
});

return alert;

 
精彩推荐