Android R : API 30 : 系统栏可见性变化回调
创始人
2024-08-15 04:30:05
0

要实现Android R中系统栏可见性变化的回调,可以使用WindowInsetsAnimation.Callback接口。下面是一个示例代码:

首先,在你的Activity中,实现WindowInsetsAnimation.Callback接口:

class MyActivity extends Activity implements WindowInsetsAnimation.Callback {
    @Override
    public void onProgress(WindowInsetsAnimation animation, List runningBounds) {
        // 系统栏可见性变化的回调
        // 在这里处理系统栏的可见性变化
    }

    @Override
    public WindowInsetsAnimation.Bounds onStart(WindowInsetsAnimation animation, WindowInsetsAnimation.Bounds bounds) {
        // 这个方法在动画开始之前调用
        // 在这里可以对系统栏的可见性进行一些初始化操作
        return bounds;
    }

    @Override
    public void onEnd(WindowInsetsAnimation animation) {
        // 这个方法在动画结束之后调用
        // 在这里可以进行一些清理操作
    }
}

然后,在你的Activity的onCreate方法中,注册WindowInsetsAnimation.Callback回调:

class MyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 获取WindowInsetsController
        WindowInsetsController insetsController = getWindow().getInsetsController();
        if (insetsController != null) {
            // 注册WindowInsetsAnimation.Callback回调
            insetsController.addOnAnimationFinishedCallback(new WindowInsetsController.OnAnimationFinishedCallback() {
                @Override
                public void onAnimationFinished(int type) {
                    // 动画结束时,移除WindowInsetsAnimation.Callback回调
                    insetsController.removeCallback(MyActivity.this);
                }
            });

            // 注册WindowInsetsAnimation.Callback回调
            insetsController.addCallback(MyActivity.this);
        }
    }
}

这样,当系统栏的可见性发生变化时,就会触发WindowInsetsAnimation.Callback中的回调方法。你可以在onProgress方法中处理系统栏的可见性变化,可以在onStart方法中进行一些初始化操作,可以在onEnd方法中进行清理操作。

请注意,这段代码只适用于Android R及以上版本。在Android R以下的版本中,可以使用其他方法来实现类似的功能。

相关内容

热门资讯

透视有挂!pokemmo脚本,... 透视有挂!pokemmo脚本,约局吧能不能开挂,扑克教程(有挂解密)1、每一步都需要思考,不同水平的...
透视代打!德普之星辅助器怎么用... 透视代打!德普之星辅助器怎么用,(德普之星)本来是有挂,新版2025教程(有挂揭秘)1、游戏颠覆性的...
透视规律“xpoker辅助工具... 透视规律“xpoker辅助工具”透视辅助脚本(果然真的是有挂)1、xpoker辅助工具ai辅助优化,...
透视ai!德普之星私人局透视,... 透视ai!德普之星私人局透视,德普之星透视软件免费入口官网,德州教程(有挂方法)透视ai!德普之星私...
透视挂“大菠萝免费辅助器”透视... 透视挂“大菠萝免费辅助器”透视辅助脚本(切实是真的有挂);1、操作简单,无需注册,只需要使用手机进行...
透视规律!德普之星透视辅助软件... 透视规律!德普之星透视辅助软件是真的吗,德普之星透视辅助,德州教程(有挂技巧)1、德普之星透视辅助软...
透视有挂!xpoker辅助怎么... 透视有挂!xpoker辅助怎么用,werplan有挂吗,wepoke教程(有挂脚本)1、完成xpok...
透视透视!德普软件,德普之星透... 透视透视!德普软件,德普之星透视辅助插件,系统教程(有挂黑科技)1、德普之星透视辅助插件ai辅助优化...
透视私人局!约局吧德州透视,p... 透视私人局!约局吧德州透视,pokemmo辅助器,靠谱教程(有挂详情);暗藏猫腻,小编详细说明约局吧...
透视有挂“sohoo poke... 透视有挂“sohoo poker辅助”透视辅助app(确实存在有挂)1、在sohoo poker辅助...