Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialog box title text size in Android

I am working on an Android application in which I want to set the text size of my dialog box. I have used the following code an XML for textview but it is only setting the size of my fields. I want to set the text size and color of my title as well.

final CharSequence[] items = { "Fake Request", "Abusive Language","Indecent Approach","Unacceptable Attitude","Dangerous Behavior",};

           ArrayAdapter<CharSequence> itemsAdapter = new
           ArrayAdapter<CharSequence> (this,
                    R.layout.menu_items, items);
           AlertDialog.Builder   builder = new AlertDialog.Builder(this);
           builder.setTitle("My Title");
           builder.setIcon(R.drawable.icon);
           builder.setAdapter(itemsAdapter, new DialogInterface.OnClickListener()
           {
               public void onClick(DialogInterface dialog, int item) {
                          switch(item) {
                                  case 0:
                              //Mark as Beautiful
                                  break;
                               case 1:
                              //Mark as Beautiful
                                  break;
                            case 2: 
                                //Mark as Not a Portrait
                                  break;
                            case 3:
                              //Mark as Offensive
                                  break;
                           case 4:
                              //Mark as Spam
                                  break;
                           case 5:
                              //cancel
                           break;
                           }
               }
           }

               );
           builder.show();

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@android:id/text1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:padding="10dip"
       android:layout_margin="5dip"
       android:gravity="center_vertical"
       android:textSize="5dip"
       android:textColor="@color/red_theme"
       android:typeface="normal"
       android:lineSpacingExtra="0dip"/>
like image 855
Usman Khan Avatar asked Feb 21 '15 07:02

Usman Khan


People also ask

How to increase TextView size in Android studio?

Go to File -> Settings, a new setting dialogue box will appear. Then go to Editor -> General. Now mark the checkbox Change font size with Ctrl + Mouse wheel and click on Apply button. Now to change your editor font size, you just have to press and hold Ctrl and rotate the Mouse wheel.

How to make text size responsive in Android?

With Android 8.0 (API level 26) and higher, you can instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView 's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.


2 Answers

If you want to do it all using styles:

<style name="MyDialog" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="android:windowTitleStyle">@style/DialogTitle</item>
</style>

<style name="DialogTitle" parent="TextAppearance.AppCompat.Large">
    <item name="android:textSize">18sp</item>
</style>

And create your dialog as such

new AlertDialog.Builder(this, R.style.MyDialog);
like image 157
zed Avatar answered Sep 27 '22 17:09

zed


//Use this code
TextView myMsg = new TextView(this);
  myMsg.setText("Succesfully send!");
  myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
  myMsg.setTextSize(20); 
  myMsg.setTextColor(Color.WHITE);
  //set custom title
        builder.setCustomTitle(myMsg);
like image 28
Surender Kumar Avatar answered Sep 27 '22 18:09

Surender Kumar