标签:获取 dcl comm theme return http res exception www
首先说下关于状态栏当系统版本为4.4或者4.4以上时可以使用沉浸式状态栏实现代码 其实状态栏这东西不是很难,就是通过添加一个跟转态栏一样的View,但是你要计算状态栏的高度不然就会出现重影或者顶上去了,哈哈!下面看看我之前怎么顶上去的,很厉害的哟!
* 动态的设置状态栏 实现沉浸式状态栏
*
*/
private void initState() {
//当系统版本为4.4或者4.4以上时可以使用沉浸式状态栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//
LinearLayout linear_bar = (LinearLayout) findViewById(R.id.ll_bar);
linear_bar.setVisibility(View.VISIBLE);
//获取到状态栏的高度
int statusHeight = getStatusBarHeight();
//动态的设置隐藏布局的高度
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) linear_bar.getLayoutParams();
params.height = statusHeight;
linear_bar.setLayoutParams(params);
}
}
/**
* 通过反射的方式获取状态栏高度
*
* @return
*/
private int getStatusBarHeight() {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
return getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}
<style name="NoStatusStyle" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item> <!--状态栏为透明,如果设置为false,则没有黑色条盖住,见下图对比-->
<item name="android:windowTranslucentNavigation">true</item> <!--导航栏为透明-->
<item name="android:statusBarColor">@android:color/holo_green_light</item>
</style>
android:fitsSystemWindows="true"
style="@style/NoStatusStyle"
1. Android 沉浸式状态栏的三种实现方式
2.Android 沉浸状态栏
写到最后:
>
结束语:
听说会点赞的人运气不会太差不信你试试!
标签:获取 dcl comm theme return http res exception www
原文地址:http://blog.csdn.net/qq_15950325/article/details/72491758