Is it possible to reduce the AlertDialog.Builder
title font size and positive button size? If yes, Just let me how to do?
Asked
Active
Viewed 9,110 times
0

Jeff Axelrod
- 27,676
- 31
- 147
- 246

bharath
- 14,283
- 16
- 57
- 95
-
you might want to check this post out http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – Sergey Benner Jan 16 '12 at 16:35
2 Answers
5
About font size you can use this:
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();
Also You can set custom title:
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);

Roman Black
- 3,501
- 1
- 22
- 31
-
it is not working for me.i need text size like 12dp or 14dp.can u tell me how can i do this – Meghna May 27 '14 at 04:46
-
I've updated my post, You can try it. You can use display metrics to get size in dp. For example: 14 * getResources().getDisplayMetrics().density; – Roman Black May 27 '14 at 06:22
3
Yo can create youtr own dialog so you can set the layout as you want:
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();
Regards.

sgallego
- 318
- 3
- 15