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!
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;
}
Have you considered percentage widths OR density independent pixels (dp)? Have a look at on Android's unit's of measurement
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.