Android沉浸式
什么是沉浸式在中国沉浸式有两个概念
沉浸式概念一 : 沉浸式表示全屏显示手机屏幕是没有手机里面自带的任何控件
沉浸式概念二 : 我要讲的就是该概念: 沉浸式就是Android屏幕上面的一条显示线,主要用于消息的提示 看图:
在Android中如果要把这个设置影藏的话要在android4.4以上
第一步自己创建一个value-19
第二步创建一个style.xml
代码:
<resources>
<!-- AppTheme 表示继承原有的样式-->
<style name="myactivity" parent="AppTheme"> <item name="android:windowTranslucentStatus">true</item> </style></resources>
第三步调用
在AndroidManifest里面调用
<activity android:name=".MainActivity" android:theme="@style/myactivity"></activity>
沉浸式如果想设置一张图片的话就在Activity里面增加一张图片
//判断版本执行
int version = getSDKVersions();//获得SDK版本
if(version>=19){
//设置抗锯齿
ImageView imageView=findViewById(R.id.status);
int height=getStatusHeight(this);
imageView.getLayoutParams().height=height;//设置高度
imageView.setBackgroundColor(Color.RED);
}
/**
* 获得状态栏的高度 就是获取抗锯齿的高度
*
* @param context
* @return
*/
public int getStatusHeight(Context context) {
int statusHeight = -1;
try {
Class clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height")
.get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusHeight;
}
//该方法是获取SDK版本的方法
public int getSDKVersions(){
return Build.VERSION.SDK_INT;
}