Android的分屏模式

Android分屏模式(Split-screen mode)是Android系统的一项实用功能,可以让用户同时在屏幕上显示两个应用,从而提高工作效率和多任务处理能力。

进入分屏模式的方法有多种,具体取决于Android版本和设备型号。以下是一些常见的方法:

长按最近使用的应用按钮: 在大多数Android设备上,长按最近使用的应用按钮即可显示最近使用的应用列表,然后拖动其中一个应用图标到屏幕边缘即可进入分屏模式。
使用手势: 在某些设备上,可以使用手势来进入分屏模式,例如向左或向右滑动屏幕边缘,或者使用三指下滑手势。
使用应用快捷方式: 某些应用支持分屏模式快捷方式,点击该快捷方式即可直接进入分屏模式。

https://blog.51cto.com/u_15162069/2763537
https://juejin.cn/post/7324384226932441124

resizeableActivity
screenLayout|orientation

<activity android:name=".MainActivity"
    android:resizeableActivity="true"
    android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

isInMultiWindowMode
onMultiWindowModeChanged

    /**
     * Called by the system when the activity changes from fullscreen mode to multi-window mode and
     * visa-versa. This method provides the same configuration that will be sent in the following
     * {@link #onConfigurationChanged(Configuration)} call after the activity enters this mode.
     *
     * @see android.R.attr#resizeableActivity
     *
     * @param isInMultiWindowMode True if the activity is in multi-window mode.
     * @param newConfig The new configuration of the activity with the state
     *                  {@param isInMultiWindowMode}.
     */
    public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
        // Left deliberately empty. There should be no side effects if a direct
        // subclass of Activity does not call super.
        onMultiWindowModeChanged(isInMultiWindowMode);
    }
    /**
     * Returns true if the activity is currently in multi-window mode.
     * @see android.R.attr#resizeableActivity
     *
     * @return True if the activity is in multi-window mode.
     */
    public boolean isInMultiWindowMode() {
        return mIsInMultiWindowMode;
    }

orientation

    /**
     * Called by the system when the device configuration changes while your
     * activity is running.  Note that this will <em>only</em> be called if
     * you have selected configurations you would like to handle with the
     * {@link android.R.attr#configChanges} attribute in your manifest.  If
     * any configuration change occurs that is not selected to be reported
     * by that attribute, then instead of reporting it the system will stop
     * and restart the activity (to have it launched with the new
     * configuration).
     *
     * <p>At the time that this function has been called, your Resources
     * object will have been updated to return resource values matching the
     * new configuration.
     *
     * @param newConfig The new device configuration.
     */
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig);
        mCalled = true;

        mFragments.dispatchConfigurationChanged(newConfig);

        if (mWindow != null) {
            // Pass the configuration changed event to the window
            mWindow.onConfigurationChanged(newConfig);
        }

        if (mActionBar != null) {
            // Do this last; the action bar will need to access
            // view changes from above.
            mActionBar.onConfigurationChanged(newConfig);
        }
    }
### Android 分屏模式下 Bar 的定制与实现 #### 修改分屏模式下的状态栏和导航栏行为 在Android系统中,分屏模式的状态栏和导航栏的行为可以通过修改`SystemUI`包来调整。具体来说,当涉及到禁用或自定义长按最近任务按钮触发的分屏操作时,主要工作集中在`NavigationBar.java`文件内[^2]。 对于希望进一步定制这些Bar的表现形式或者交互逻辑的情况: - **状态栏**:通常位于屏幕顶部,显示时间、电量以及通知图标等内容。要改变其外观或功能,需编辑`com.android.systemui.statusbar.phone.StatusBar`类及其关联资源文件。 - **导航栏**:处于屏幕底部(传统布局),包含了返回、主页和多任务管理三个核心按键。针对此部分的改动同样围绕着`com.android.systemui.navigationbar.NavigationBar`展开。特别是如果想要移除特定手势支持或是重新映射输入事件,则应关注于该Java源码内部的方法重写与监听器设置。 为了确保更改后的效果能够适配不同设备尺寸并保持良好的用户体验,建议开发者参照官方文档关于最小可调整窗口大小(`mMinimalSizeResizableTask`)的规定来进行相应设定[^3]。 另外值得注意的是,在较新版本的操作系统里,Google可能已经对上述组件进行了重构优化;因此实际开发过程中还需结合目标平台的具体情况进行探索验证。 ```java // 示例代码片段展示如何获取默认最小可调整任务窗口宽度 int minWindowSize = context.getResources().getDimensionPixelSize( com.android.internal.R.dimen.default_minimal_size_resizable_task); ``` 通过以上方式可以有效地控制应用在进入分屏或多窗口状态下所占用的空间比例,并且不影响整体视觉风格的一致性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值