对于状态栏相关适配这个事情,真是让人头疼的一个模块。因为负责的项目主题色偏偏是白色,不但要去适配 MIUI ,Flyme(因为这两个都可以实现沉浸式,并且图标可以切换成黑色),也要分别适配 Android 6.0 以下, Android 6.0 起两种不同情况(6.0 起原生提供了高亮状态栏模式,该模式下状态栏图标可以切换成黑色)。一大堆坑,坑到自己都怕......
现在就把一些相关实用的方法、注意点汇集起来,并推荐一些相关实用的库。
首先放代码:
BuildProperties.java
public class BuildProperties {
private final Properties properties;
private BuildProperties() throws IOException {
properties = new Properties();
properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
}
public boolean containsKey(final Object key) {
return properties.containsKey(key);
}
public boolean containsValue(final Object value) {
return properties.containsValue(value);
}
public Set<Map.Entry<Object, Object>> entrySet() {
return properties.entrySet();
}
public String getProperty(final String name) {
return properties.getProperty(name);
}
public String getProperty(final String name, final String defaultValue) {
return properties.getProperty(name, defaultValue);
}
public boolean isEmpty() {
return properties.isEmpty();
}
public Enumeration<Object> keys() {
return properties.keys();
}
public Set<Object> keySet() {
return properties.keySet();
}
public int size() {
return properties.size();
}
public Collection<Object> values() {
return properties.values();
}
public static BuildProperties newInstance() throws IOException {
return new BuildProperties();
}
}
OSHelper.java
public class OSHelper {
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
private static boolean isTranslucentStatusMiUi;
private static boolean isFlyMe;
static {
isTranslucentStatu