feat(android): 添加多个新模块并更新系统栏适配逻辑
- 在settings.gradle中引入多个新模块,包括we88sg26、NEPSPIN88、2URUS等 - 更新各新模块build.gradle配置,修改应用ID、资源颜色、应用名、用户ID等信息 - 替换各新模块google-services.json配置,更新Firebase项目参数和API密钥 - 优化MainActivity、NotifyListActivity、WebViewActivity中的系统栏适配逻辑 - 引入WindowCompat和WindowInsetsControllerCompat支持,实现沉浸式状态栏和导航栏处理 - 通过applySystemBarInsets方法统一处理系统栏颜色和内边距,提高多版本兼容性 - 删除过时的enableEdgeToEdge方法,代码简化并提升可维护性 - 设置系统栏状态图标颜色亮度基于背景色亮度计算,提升视觉效果一致性
This commit is contained in:
@@ -116,24 +116,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (styleColor != 0) {
|
||||
getWindow().setNavigationBarColor(styleColor);
|
||||
}
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
View decor = getWindow().getDecorView();
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
if (isWhite) {
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
} else {
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.hide();
|
||||
}
|
||||
activityMain2Binding = ActivityMain2Binding.inflate(getLayoutInflater());
|
||||
setContentView(activityMain2Binding.getRoot());
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S) {
|
||||
enableEdgeToEdge(getWindow(), activityMain2Binding.getRoot());
|
||||
}
|
||||
applySystemBarInsets(getWindow(), activityMain2Binding.getRoot());
|
||||
String body = getIntent().getStringExtra("message");
|
||||
if (!TextUtils.isEmpty(body)) {
|
||||
MessageInfo messageInfo = GsonUtils.getObjFromJSON(body, MessageInfo.class);
|
||||
@@ -349,18 +340,31 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void enableEdgeToEdge(Window window, View rootView) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true);
|
||||
/** Keeps WebView content out of status/navigation bar areas on every Android version. */
|
||||
public void applySystemBarInsets(Window window, View rootView) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false);
|
||||
if (windowsColor != 0) {
|
||||
rootView.setBackgroundColor(windowsColor);
|
||||
window.setStatusBarColor(windowsColor);
|
||||
}
|
||||
window.setNavigationBarColor(styleColor);
|
||||
WindowInsetsControllerCompat insetsController = WindowCompat.getInsetsController(window, window.getDecorView());
|
||||
insetsController.setAppearanceLightStatusBars(!isWhite);
|
||||
insetsController.setAppearanceLightNavigationBars(isWhite);
|
||||
boolean useDarkSystemIcons = isLightColor(windowsColor);
|
||||
insetsController.setAppearanceLightStatusBars(useDarkSystemIcons);
|
||||
insetsController.setAppearanceLightNavigationBars(useDarkSystemIcons);
|
||||
insetsController.show(WindowInsetsCompat.Type.statusBars() | WindowInsetsCompat.Type.navigationBars());
|
||||
ViewCompat.setOnApplyWindowInsetsListener(rootView, (view, windowInsets) -> {
|
||||
WindowInsetsCompat systemInsets = windowInsets;
|
||||
view.setPadding(0, systemInsets.getStableInsetTop(), 0, systemInsets.getStableInsetBottom() // 底部内边距设为0,由占位View填充
|
||||
);
|
||||
androidx.core.graphics.Insets systemBars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return WindowInsetsCompat.CONSUMED;
|
||||
});
|
||||
ViewCompat.requestApplyInsets(rootView);
|
||||
}
|
||||
|
||||
private static boolean isLightColor(int color) {
|
||||
double luminance = (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255d;
|
||||
return luminance > 0.6d;
|
||||
}
|
||||
|
||||
private void toLink() {
|
||||
|
||||
@@ -46,18 +46,15 @@ public class NotifyListActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
userId = MainActivity.getInt(NotifyListActivity.this,"user_code",userId);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
super.onCreate(savedInstanceState);
|
||||
View decor = getWindow().getDecorView();
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.hide();
|
||||
}
|
||||
activityNotifylistBinding = ActivityNotifylistBinding.inflate(getLayoutInflater());
|
||||
setContentView(activityNotifylistBinding.getRoot());
|
||||
enableEdgeToEdge(getWindow(), activityNotifylistBinding.getRoot(), true, false);
|
||||
applySystemBarInsets(getWindow(), activityNotifylistBinding.getRoot(), true, false);
|
||||
messageInfoItem = (MessageInfo) getIntent().getSerializableExtra("message");
|
||||
activityNotifylistBinding.backIv.setOnClickListener(view -> finish());
|
||||
manager = new LinearLayoutManager(this);
|
||||
@@ -102,9 +99,9 @@ public class NotifyListActivity extends AppCompatActivity {
|
||||
* *
|
||||
* @param isLightNavigationBar 导航栏文字是否为浅色(仅Android O+生效)
|
||||
*/
|
||||
public void enableEdgeToEdge(Window window, View rootView,
|
||||
public void applySystemBarInsets(Window window, View rootView,
|
||||
boolean isLightStatusBar, boolean isLightNavigationBar) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true);
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false);
|
||||
|
||||
// 3. 直接设置导航栏颜色(兼容所有版本)
|
||||
window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
@@ -114,8 +111,12 @@ public class NotifyListActivity extends AppCompatActivity {
|
||||
// true=浅色文字(白色),false=深色文字(黑色),根据导航栏颜色调整
|
||||
insetsController.setAppearanceLightNavigationBars(isLightNavigationBar);
|
||||
window.getDecorView().setBackgroundColor(Color.WHITE);
|
||||
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(rootView, (view, insets) -> {
|
||||
androidx.core.graphics.Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return WindowInsetsCompat.CONSUMED;
|
||||
});
|
||||
ViewCompat.requestApplyInsets(rootView);
|
||||
}
|
||||
|
||||
public void getNotifyList() {
|
||||
|
||||
@@ -26,6 +26,10 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.core.view.WindowInsetsControllerCompat;
|
||||
import com.king.app.updater.AppUpdater;
|
||||
import com.webclip.base.databinding.ActivityMain2Binding;
|
||||
|
||||
@@ -51,23 +55,37 @@ public class WebViewActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
getWindow().setNavigationBarColor(getColor(R.color.white));
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
View decor = getWindow().getDecorView();
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.hide();
|
||||
}
|
||||
activityMain2Binding = ActivityMain2Binding.inflate(getLayoutInflater());
|
||||
setContentView(activityMain2Binding.getRoot());
|
||||
applySystemBarInsets();
|
||||
activityMain2Binding.backIv.setOnClickListener(view -> finish());
|
||||
url = getIntent().getStringExtra("url");
|
||||
initView();
|
||||
}
|
||||
|
||||
private void applySystemBarInsets() {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
|
||||
WindowInsetsControllerCompat controller = WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
|
||||
controller.setAppearanceLightStatusBars(true);
|
||||
controller.setAppearanceLightNavigationBars(true);
|
||||
controller.show(WindowInsetsCompat.Type.statusBars() | WindowInsetsCompat.Type.navigationBars());
|
||||
View root = activityMain2Binding.getRoot();
|
||||
ViewCompat.setOnApplyWindowInsetsListener(root, (view, insets) -> {
|
||||
androidx.core.graphics.Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return WindowInsetsCompat.CONSUMED;
|
||||
});
|
||||
ViewCompat.requestApplyInsets(root);
|
||||
}
|
||||
|
||||
private ValueCallback<Uri[]> mUploadCallbackForHighApi;
|
||||
|
||||
public void initView() {
|
||||
|
||||
Reference in New Issue
Block a user