0

I have created a custom theme to define the size of the title bar and its background style. This is the code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="customTheme" parent="android:Theme"> 
        <item name="android:windowTitleSize">53px</item>
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>   
            <item name="android:windowContentOverlay">@android:color/transparent</item>
    </style> 
</resources>

The problem is that I am setting a fixed size for this title bar instead of using different values depending on whether the device is using hdpi/mdpi or ldpi icons.

What should be done here? I tried adding the theme and styles to the drawable directory but obviously this is wrong.

Thanks!

Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158

2 Answers2

1

I don't know if this will help you, but you can detect programatically screen density. I didn't worked with custom title bar so i don't know if you can change titlesize programatically.

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        switch(metrics.densityDpi){
             case DisplayMetrics.DENSITY_LOW:
                 **
                        break;
             case DisplayMetrics.DENSITY_MEDIUM:
                 **
                         break;
             case DisplayMetrics.DENSITY_HIGH:
                **
                         break;
        }
artouiros
  • 3,947
  • 12
  • 41
  • 54
1

Have you considered percentage widths OR density independent pixels (dp)? Have a look at on Android's unit's of measurement

Community
  • 1
  • 1
Tanner Perrien
  • 3,133
  • 1
  • 28
  • 35