rizzz86
rizzz86

Reputation: 3990

How to Change Height of Custom Dialog's Title Bar in Android

In my android app I have a custom dialog box. I want to set the height of dialog's Title bar. My style is as follows:

<resources>
    <style name="customDialogStyle" parent="android:Theme.Dialog"> 
        <item name="android:background">#04a9ee</item>
        <item name="android:height">5dp</item> 
     </style> 
</resources>

But there is no effect of "height" attribute on title bar. So, how can the height of custom dialog's title bar can be changed ?

Upvotes: 3

Views: 6056

Answers (2)

kelvincer
kelvincer

Reputation: 6138

This works for me

Your theme:

  <resources>
       <style name="MyDialog" parent="android:Theme.Holo.Dialog">
           .......

       </style>

  </resources>

Your Custom Dialog Class:

  public class CustomDialog extends Dialog
  {
       public CustomDialog(Context context, int theme) {
           super(context, theme);
       }


       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          ........... 

          Resources res = getContext().getResources();
          int titleId = res.getIdentifier("title", "id", "android");
          View title = findViewById(titleId);
          if (title != null) {
              title.getLayoutParams().height = 5; // your height
          }
       }
  }

Create dialog and show in your code:

   CustomDialog customDialog = new CustomDialog(this, R.style.MyDialog);
   customDialog.show();

Upvotes: 2

SnowyTracks
SnowyTracks

Reputation: 1985

Yeh I just check, you want to use "android:layout_height" other heights you can use also like: "android:minHeight"

Upvotes: 2

Related Questions