2016-04-01 43 views
0

你好高级开发人员。如何在android上控制alertdialog按钮的文字大小?

最近我创建了alertdialog。

我知道标题的大小,邮件大小控制研究

,但我不知道控制研究按钮上的文字大小

如何控制研究按钮上的文字大小?

我必须这种格式请 谢谢。

View view = getLayoutInflater().inflate(R.layout.connecting_error_dialog, null); 
     TextView txtTitle = (TextView) view.findViewById(R.id.title); 
     txtTitle.setTextSize(40); 
     txtTitle.setTextColor(Color.RED); 
     txtTitle.setText("fail"); 

     TextView message = (TextView) view.findViewById(R.id.message); 
     message.setTextSize(30); 
     message.setText("dddddd"); 

     AlertDialog.Builder builder = new AlertDialog.Builder(Connectingreceiver.this); 
     builder.setView(view) 
       .setCancelable(false) 
       .setPositiveButton("ok", 
         new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, int which) { 
           moveTaskToBack(true); 
           finish(); 
           android.os.Process.killProcess(android.os.Process.myPid()); 
          } 
         }); 
     AlertDialog alertDialog = builder.create(); 
     alertDialog.show(); 





<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="10dp"> 
    <LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView android:id="@+id/title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="HelloAlert!"/> 
    <TextView android:id="@+id/message" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingTop="10dip"/> 
</LinearLayout> 

+0

你试过了什么?究竟发生了什么问题?你有任何错误?那些错误是什么?你试图做什么来修复这些错误?当你这样做时发生了什么?请记住在提出问题时包含这些内容。按照本指南确保您的问题质量很高:https://stackoverflow.com/help/how-to-ask –

回答

3

需要创建第一个警告对话框,然后它的元素也变为改变。

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("desired font size"); 

    Button btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE); 
    btnNegative.setTextSize("desired font size"); 
    } 
}); 

return alert; 
+0

谢谢,我完成 –

相关问题