qt安卓 沉浸式
作者:互联网
package an.qt.QtFullscreenActivityAPP;//指明文件包名
import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
import android.util.Log;
import android.os.Bundle;
import android.os.Build;
import android.graphics.Color;
import android.view.WindowManager;
import android.view.View;
public class QtFullscreenActivety extends org.qtproject.qt5.android.bindings.QtActivity
{
private final static String TAG = "QtFullscreen";
private static Context context;
@Override
public void onCreate(Bundle saveInstanceState)
{
super.onCreate(saveInstanceState);
// //样式1 半透明黑色阴影
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// getWindow().getDecorView().setFitsSystemWindows(true);
context = getApplicationContext();
//样式2 全透明
this.setStatusBarFullTransparent();
// //样式3 纯色
// this.setStatusBarColor("#ff0000");
}
//全局获取Context
public static Context getContext() {
return context;
}
//全透状态栏
private void setStatusBarFullTransparent()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//透明状态栏
// 状态栏字体设置为深色,SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 为SDK23增加
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
// 部分机型的statusbar会有半透明的黑色背景
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);// SDK21
}
}
// 非全透,带颜色的状态栏,需要指定颜色
private void setStatusBarColor(String color){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// 需要安卓版本大于5.0以上
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(Color.parseColor(color));
}
}
}
标签:沉浸,qt,安卓,WindowManager,FLAG,Build,import,getWindow,android 来源: https://www.cnblogs.com/nocanstillbb/p/16316273.html