安卓沉浸式狀態列

2021-09-04 05:06:41 字數 2680 閱讀 6200

public class statusbarcompat 

return;

}//當前手機版本為4.4

if (build.version.sdk_int >= build.version_codes.kitkat && build.version.sdk_int < build.version_codes.lollipop)

view statusbarview = new view(activity);

viewgroup.layoutparams lp = new viewgroup.layoutparams(viewgroup.layoutparams.match_parent,

getstatusbarheight(activity));

statusbarview.setbackgroundcolor(color);

contentview.addview(statusbarview, lp);}}

public static void compat(activity activity)

public static int getstatusbarheight(context context)

return result;

}/**

* 修改狀態列為全透明,並且不影響導航欄顏色,0919親測好使

** @param activity

*/@targetapi(19)

public static void transparencybar(activity activity) else if (build.version.sdk_int >= build.version_codes.kitkat)

if (statusbarcompat.getsystem().equals(statusbarcompat.sys_miui)) catch (nosuchmethodexception e) catch (classnotfoundexception e) catch (nosuchfieldexception e) catch (illegalacces***ception e) catch (illegalargumentexception e) catch (invocationtargetexception e)

} else

} else if (statusbarcompat.getsystem().equals(statusbarcompat.sys_flyme)) else if (build.version.sdk_int >= build.version_codes.m) else

}/**

* 修改狀態列為全透明,並且不影響導航欄顏色,0919親測好使

** @param activity

*/@targetapi(19)

public static void transparencybar(activity activity, int color) else if (build.version.sdk_int >= build.version_codes.kitkat)

if (statusbarcompat.getsystem().equals(statusbarcompat.sys_miui)) catch (nosuchmethodexception e) catch (classnotfoundexception e) catch (nosuchfieldexception e) catch (illegalacces***ception e) catch (illegalargumentexception e) catch (invocationtargetexception e)

} else

} else if (statusbarcompat.getsystem().equals(statusbarcompat.sys_flyme)) else if (build.version.sdk_int >= build.version_codes.m) else

}public static string getsystem() else if (prop.getproperty(key_emui_api_level, null) != null

|| prop.getproperty(key_emui_version, null) != null

|| prop.getproperty(key_emui_config_hw_sys_version, null) != null) else if (getmeizuflymeosflag().tolowercase().contains("flyme"))

} catch (ioexception e)

return sys;

}public static string getmeizuflymeosflag()

private static string getsystemproperty(string key, string defaultvalue) catch (exception e)

return defaultvalue;

}}

使用:

statusbarcompat.transparencybar(this);
statusbarcompat.compat(this, color.parsecolor("#a5b4bb"));

安卓沉浸式狀態列

activity的子fragment的標題頂到狀態列 當乙個activity介面下有4個同級的fragment的時候,首頁的fragment頂部是的時候,設定了透明狀態列之後就會造成其他介面的標題頂到狀態列中,這個時候只需要設定一下標題布局在父控制項的layoutparams,layoutparam...

安卓狀態列問題詳解大全(沉浸式狀態列)

1.解決頂部問題 2安卓透明狀態列和底部操作欄 在setcontentview 前面加上以下 解決底部重疊的問題 具體顏色自行修改 private void setstaus 3沉浸式狀態列 rl bar title這個布局是空的linnearlayout 放到headview的上面 protect...

安卓沉浸式狀態列初體驗

初次接觸沉浸式,本文先從純色入手。安卓狀態列沉浸式從大於等於19即安卓4.4開始有了第一種實現方案即使用systembartintmanager window window activity.getwindow window.setflags windowmanager.layoutparams.f...