递归火山软件开发平台

标题: 安卓setcolor以下全嵌入导致报错怎么办? [打印本页]

作者: zhouchao0118    时间: 2024-9-10 14:16
标题: 安卓setcolor以下全嵌入导致报错怎么办?

    public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.噜阿噜LIPOP) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
            View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
            if (fakeStatusBarView != null) {
                if (fakeStatusBarView.getVisibility() == View.GONE) {
                    fakeStatusBarView.setVisibility(View.VISIBLE);
                }
                fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            } else {
                decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
            }
            setRootView(activity);
        }
    }
其实没报错,因为我还没运行,但是就算不运行,我也知道一定会报错。
因为火山里的安卓窗口类,是不存在getWindow()方法的。
所以像这样写的话,肯定会报错
(, 下载次数: 5)
所以,要去封装getWindow()方法吗?
而getWindow()的返回值是android.view.window类
而window类会导入WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
(, 下载次数: 5)
也就是说,无论如何,都会和自定义组件属性扯上关系。
所以,现在怎么办?
用@begin@end吗?


作者: 创世魂    时间: 2024-9-10 14:26
没导入 WindowManager 包吧,怎么可能和自定义组件属性扯上关系……这俩都没关系。




欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/) Powered by Discuz! X3.4