[英]Android - How to create themes that depend on screen resolutions?
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.问题是我为此标题栏设置了固定大小,而不是根据设备使用的是 hdpi/mdpi 还是 ldpi 图标使用不同的值。
What should be done here?这里应该做什么? I tried adding the theme and styles to the drawable directory but obviously this is wrong.
我尝试将主题和 styles 添加到可绘制目录但显然这是错误的。
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)?您是否考虑过百分比宽度或与密度无关的像素 (dp)? Have a look at on Android's unit's of measurement
看看 Android 的测量单位
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.