I created a custom dialog but I got an unexpected result.
The final appearance of the dialog is:
As you can see, my custom dialog is shown with a kind of padding in both top and bottom of the dialog, and I don't code it to do this...
The code is the next:
#Override
protected Dialog onCreateDialog(int id){
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newAsig = inflater.inflate(R.layout.nuevaasignatura_act, null);
//Also, down here I tried to shape the dialog by setting a functional resource, but
//the stroke should be blue, not grey.
RelativeLayout re = (RelativeLayout)newAsig.findViewById(R.id.layoutCrearAsig1);
re.setBackgroundResource(R.drawable.borde);
Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
ImageView ico = (ImageView)newAsig.findViewById(R.id.ivicono);
ico.setBackgroundResource(R.drawable.colorprincipal);
LinearLayout ly = (LinearLayout)newAsig.findViewById(R.id.layoutCrearAsig2);
ly.setBackgroundColor(Color.rgb(214, 217, 224));
TextView txt = (TextView)newAsig.findViewById(R.id.textviewnuevaasig);
txt.setTypeface(tf);
TextView txt1 = (TextView)newAsig.findViewById(R.id.textViewCarpeta);
txt1.setTypeface(tf);
txt1.setBackgroundResource(R.drawable.colorprincipal);
Button btn = (Button)newAsig.findViewById(R.id.buttonCrearAsig);
btn.setTypeface(tf);
switch (id){
case 0:
return new AlertDialog.Builder(this)
.setView(newAsig).create();
}return null;
And the XML file...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layoutCrearAsig1">
<ImageView
android:id="#+id/ivicono"
android:layout_width="50dp"
android:layout_height="50dp"
android:paddingLeft="4dp"
android:background="#color/DarkGray"
android:contentDescription="Icono ClassMarks"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="#drawable/icono_cm" />
<TextView
android:id="#+id/textViewCarpeta"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_toRightOf="#id/ivicono"
android:background="#color/DarkGray"
android:clickable="true"
android:gravity="center"
android:text="Carpeta"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="#+id/layoutCrearAsig2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/ivicono"
android:orientation="vertical">
<TextView
android:id="#+id/textviewnuevaasig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Crear nueva asignatura"
android:textSize="20sp" />
<EditText
android:id="#+id/edittextAsig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp" >
</EditText>
<Button
android:id="#+id/buttonCrearAsig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="20sp"
android:text="Crear"/>
</LinearLayout>
</RelativeLayout>
I hope you can help me. Thanks!
The idea is AlertDialog always has 5dp top and bottom padding.
Try something like this:
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setView(newAsig, 0, 0, 0, 0);
Try this validation.
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
builder = new AlertDialog.Builder(getActivity());
builder.setInverseBackgroundForced(true);
} else {
builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
}
}
Related
How to remove the empty space in the dialog. My code-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_2x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_2x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_point_25_x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_point_25_x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.25X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_normal_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_75x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_75x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.75X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
</LinearLayout>
My Java Code
View alertLayout = View.inflate(this, R.layout.quality_dialog_layout, null);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(alertLayout);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
Suggestion 1:
In order to customize the AlertDialog theme you have to create a new theme for it, which is a bit complicated and quite hard as you have also to create proper images etc.
Regarding this option you can check this topic here
Suggestion 2:
Include the button in the xml:
<Button android:text="OK"
style="?android:attr/borderlessButtonStyle" />
Suggestion 3:
Use the AlertDialog options and don't change the theme, this will add proper spacing in all options and follow the android theming so it will not look strange, but will not remove the spacing you mentioned:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setSingleChoiceItems(R.array.your_array_options, null/* no item preselected*/,
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// handle the item selection here
}
}
);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
and the your_array_options will be in a file res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="your_array_options">
<item>2X</item>
<item>1.5X</item>
<item>1.25X</item>
...
</string-array>
</resources>
Suggestion 4:
In order to have full customized theme then do not use AlertDialog at all but DialogFragment:
public class MyDialogFragment extends DialogFragment {
// ...
// Empty constructor required for DialogFragment
public MyDialogFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quality_dialog_layout, container);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
// This will also require to add extra buttons in the xml!
// getDialog().setTitle("If you want to change the title");
return view;
}
}
ProgressDialog is depracted thats why I create a layout and put a progressbar and a textview and put this layout into a dialog. Until now, everything works well but in runtime I cannot change the textview's text.
Here is my code (in OnCreate Method was called)
View progressLayout = LayoutInflater.FromContext(this).Inflate(Resource.Layout.progressbar,null);
var txtMessage = progressLayout.FindViewById<TextView>(Resource.Id.loading_msg);
txtMessage.Text = "My message is this";
txtMessage.SetText("my tesst", TextView.BufferType.Normal);
progressLayout.FindViewById<TextView>(Resource.Id.loading_msg)
.SetText("hobaa",TextView.BufferType.Normal);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetView(Resource.Layout.progressbar);
Dialog dialog = builder.Create();
dialog.SetTitle("My Title");
dialog.SetCancelable(false);
dialog.Show();
and my progress.axml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="13dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/loader"
android:layout_marginEnd="5dp"
android:layout_width="45dp"
android:layout_height="45dp"
/>
<TextView
android:layout_width="wrap_content"
android:text="Loading..."
android:textAppearance="?android:textAppearanceSmall"
android:layout_gravity="center_vertical"
android:id="#+id/loading_msg"
android:layout_toEndOf="#+id/loader"
android:layout_height="wrap_content" />
</LinearLayout>
Change this
builder.SetView(Resource.Layout.progressbar);
to
builder.SetView(progressLayout);
I had problems with this when I was programming it. I thought I'd cured it by specifying a fixed percentage height for the body of the dialog. I thought this was bad form, because the user might have a slim display, or set large fonts, which would cut of the EditText box.
Anyway that solution has failed beyond the emulator.
It looks like Android is assigning a fixed height to a dialog, and if my custom title has devoured too much of this height, squeezing everything else off. Is this correct and how do I fix it?
Problem
public class GetUserNameDialogFragment extends DialogFragment {
final String TAG = "GetUserNameDialog";
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle);
//TODO getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = getActivity().getLayoutInflater();
final View sunburst =inflater.inflate(R.layout.dialog_user_name, null);
builder.setView(sunburst);
builder.setCancelable(false)
.setPositiveButton("Let's go!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.wtf(TAG, "button press");
EditText name = (EditText) sunburst.findViewById(R.id.nameEditText);
String userName = name.getText().toString().trim();
//TODO needs to be validated
SharedPreferences sharedPref = getActivity().getSharedPreferences("userDetails", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("userName", userName );
editor.commit();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Here's the xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="#drawable/ic_ball_sunburst_classic"
android:background="#color/colorAccent"
/>
<LinearLayout
android:layout_width="250dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_height="125dp">
<EditText
android:id="#+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:hint="Enter your first name"/>
</LinearLayout>
</LinearLayout>
All help very much appreciated, the first impression of my app - what a disaster!
Why don't you use Dialog instead of AlertDialog ?
I built the example using a Dialog and it works perfectly
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:layout_width=" 290dp"
android:layout_height="wrap_content"
android:background="#4CAF50">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/base"
android:background="#color/colorAccent"
/>
<EditText
android:textColor="#fff"
android:textColorHint="#fff"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:id="#+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your first name"/>
<Button
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:id="#+id/letsGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Let's Go"
android:textColor="#fff"
android:background="#android:color/transparent"/>
final Dialog dialog = new Dialog(context);
if(dialog.getWindow() != null){
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
dialog.setContentView(R.layout.dialog);
Button letsGO = (Button) dialog.findViewById(R.id.letsGo);
EditText nameEditText = (EditText) dialog.findViewById(R.id.nameEditText);
letsGO.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Lets GO!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
dialog.show();
This question already has answers here:
Dialog with transparent background in Android
(25 answers)
Closed 6 years ago.
I have a DialogFragment class with following code:
public class LeavingAppDialog extends DialogFragment {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.leaving_app_dialog, null);
builder.setView(v);
Typeface segoeuib = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "fonts/segoeuib.ttf");
TextView text = (TextView) v.findViewById(R.id.msg_dialog);
text.setTypeface(segoeuib);
Dialog dialog = builder.create();
return dialog;
}
}
This dialog uses a custom layout, here is its code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="#+id/imageView"
android:src="#drawable/box_1_fit"
android:scaleType="centerInside"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#00000000" />
<FrameLayout
android:layout_width="275dp"
android:layout_height="150dp"
android:id="#+id/frameLayout"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="LEAVING THIS APP?"
android:id="#+id/msg_dialog"
android:textSize="35dp"
android:layout_gravity="center_horizontal|top"
android:gravity="center_horizontal|top"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</FrameLayout>
<Button
android:layout_width="100dp"
android:layout_height="37dp"
android:id="#+id/btn_cancel"
android:background="#drawable/cancel_button_fit"
android:singleLine="false"
android:layout_alignRight="#+id/frameLayout"
android:layout_alignEnd="#+id/frameLayout"
android:layout_marginTop="75dp"
android:layout_below="#+id/frameLayout"
android:layout_marginRight="25dp"
android:onClick="ExitApp"/>
<Button
android:layout_width="100dp"
android:layout_height="37dp"
android:id="#+id/btn_accept"
android:background="#drawable/accept_button_fit"
android:layout_below="#+id/frameLayout"
android:layout_alignLeft="#+id/frameLayout"
android:layout_alignStart="#+id/frameLayout"
android:layout_marginTop="75dp"
android:layout_marginLeft="25dp"
android:onClick="ExitApp"/>
</RelativeLayout>
</RelativeLayout>
The problem is on the screenshot. I need to get rid of these white borders. I've tried to set background color to transparent through layout editor and through code. I've tried to set transparent backgound color to all the layouts and to the image itself, but it all had no effect. My source image is a png file and it really has transparent background, so the problem is not in the source image.
Set Background Transparent:
Like this: mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Try this Custom Alert Dialog Class:
class CustomAlertDialog extends AlertDialog {
CustomAlertDialog(Context context) {
super(context);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
setContentView(R.layout.view_custom_alert_dialog);
RMTextView txtTitle = (RMTextView) findViewById(R.id.txt_alert_title);
txtTitle.setText("Title");
}
}
try this way.
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// mDialog.getWindow().setBackgroundDrawableResource("#0069ad");
mDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
In my code dialog2.setTitle("FeedBack"); is shown in a white color. How do I change title change color? Because my layout background is white so I can't see it. How do I change dialog title color?
public Dialog dialog2;
ImageView b = (ImageView) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog2 = new Dialog(context);
View vLoad = LayoutInflater.from(fifthscreen.this).inflate(R.layout.timer, null);
dialog2.setContentView(vLoad);
dialog2.setTitle("FeedBack");
dialog2.setCancelable(false);
dialog2.show();
}
});
}
////////////timer.xml///////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:id="#+id/layouttimer">
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="15dp"
android:textColor="#000000" ></TextView>
<Button
android:id="#+id/FeedbackYummiSlice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=" YumiiSlice" >
</Button>
<Button
android:id="#+id/FeedbackThisdish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=" Feedback This dish " >
</Button>
<Button
android:id="#+id/nothanks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=" No,Thanks " >
</Button>
</LinearLayout>
The method setCustomTitle(View customTitleView) allows you to do that. You need to create a layout to set in this, and in that layout simply set to the TextView the style you want.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customTitleView = inflater.inflate(R.layout.custom_title_view, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCustomTitle(customTitleView);
Please refer This Answer for more information.