Android 如何减少AlertDialog.Builder标题字体大小和正按钮大小?
是否可以减小Android 如何减少AlertDialog.Builder标题字体大小和正按钮大小?,android,android-alertdialog,Android,Android Alertdialog,是否可以减小AlertDialog.Builder标题字体大小和正按钮大小?如果是,请告诉我怎么做?关于字体大小,您可以使用以下方法: SpannableStringBuilder ssBuilser = new SpannableStringBuilder("Sample"); StyleSpan span = new StyleSpan(Typeface.ITALIC); ScaleXSpan span1 = new ScaleXSpan(1); ssBuilser.setSpan(span
AlertDialog.Builder
标题字体大小和正按钮大小?如果是,请告诉我怎么做?关于字体大小,您可以使用以下方法:
SpannableStringBuilder ssBuilser = new SpannableStringBuilder("Sample");
StyleSpan span = new StyleSpan(Typeface.ITALIC);
ScaleXSpan span1 = new ScaleXSpan(1);
ssBuilser.setSpan(span, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssBuilser.setSpan(span1, 0, 5, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(ssBuilser);
builder.show();
您还可以设置自定义标题:
float size = 25;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final TextView myView = new TextView(getApplicationContext());
myView.setText("A Sample Title to Change Dialog Title");
myView.setTextSize(size);
builder.setCustomTitle(myView);
您可以创建自己的对话框,以便根据需要设置布局:
Dialog dialog = new Dialog(act,R.style.MyTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setOwnerActivity(act);
//In the layout XML you can set the text size or the button size.
dialog.setContentView(R.layout.dialog_layout);
TextView text = (TextView) dialog.findViewById(R.id.text);
//you can set your text size here
text.setTextSize(mySize);
text.setText("my text");
Button ok = (Button) dialog.findViewById(R.id.ok);
//you can change the button dimensions here
ok.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
//actions
}
});
dialog.show();
问候。你可能想看看这篇文章,它对我不起作用。我需要像12dp或14dp这样的文本大小。你能告诉我怎么做吗?我已经更新了我的文章,你可以试试。您可以使用显示度量来获取dp中的大小。例如:14*getResources().getDisplayMetrics().density;