欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android P FreeForm*窗口模式简单实现

程序员文章站 2024-01-27 12:21:04
...

开启系统FreeForm模式。
adb shell settings put global enable_freeform_support 1
adb shell settings put global force_resizable_activities 1

/frameworks/native/data/etc/android.software.freeform_window_management.xml
push到目录system/etc/permissions/

代码如下:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = new Intent(this, FreeFormActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);

        //ActivityOptions activityOptions = ActivityOptions.makeBasic();
        //activityOptions.setLaunchWindowingMode(5);
        ActivityOptions activityOptions = getActivityOptions(this);
        int left = 200;
        int top = 100;
        int right = 600;
        int bottom = 200;
        activityOptions.setLaunchBounds(new Rect(left,top,right,bottom));
        Bundle bundle = activityOptions.toBundle();
        startActivity(intent,bundle);
    }

    public static ActivityOptions getActivityOptions(Context context) {
        ActivityOptions options = ActivityOptions.makeBasic();
        int freeform_stackId = 5;
        try {
            Method method = ActivityOptions.class.getMethod("setLaunchWindowingMode", int.class);
            method.invoke(options, freeform_stackId);
            Log.i("FreeForm","sunxiaolin,getActivityOptions freeform_stackId = " + freeform_stackId);
        } catch (Exception e) {
            /* Gracefully fail */
            Log.i("FreeForm","sunxiaolin,getActivityOptions e = " + e);
        }

        return options;
    }
}

FreeFormActivity是一个只显示文本“Hello FreeForm!”的Activity.

效果图:
Android P FreeForm*窗口模式简单实现

相关标签: FreeForm *窗口