带有侧边栏的android多窗口启动器

问题描述

我想创建一个如下所示的应用程序。

  • 将有一个永远在线的侧边栏(透明)。
  • 如果用户侧边栏上滑动,则会在当前应用上打开一个小屏幕。 迷你屏幕将再次启动用户的主屏幕/应用程序抽屉。用户将能够在其上运行任何应用程序。两个应用程序将同时运行(主屏幕和小屏幕应用程序)

enter image description here

到目前为止我所做的

  • 我创建了一个应用程序,它获取所有包名称、应用程序名称和图标,并将它们显示侧边栏中。 (在抽屉布局中使用自定义列表视图)

  • 当我点击任何项目时,它会以窗口模式打开。

问题部分

当我在窗口模式下打开应用程序时,侧边栏关闭。但我希望侧边栏保持不变,然后在主屏幕顶部以窗口模式显示打开的应用程序。

那么如何解决这个问题,我想知道我是否遵循正确的轨道来完成任务或 有更好的方法吗?

XML 文件


<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    android:background="@color/cardview_light_background">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Swipe Right"
        android:textSize="15dp"
        android:textColor="#D50000"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Open App In\nMultiWIndow Mode"
        android:textSize="30sp"
        android:gravity="center"
        android:textStyle="bold"
        android:textColor="@color/black"/>


    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            tools:context=".MainActivity2">

            <ListView
                android:id="@+id/listView"
                android:layout_width="280dp"
                android:layout_height="0dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="10dp"
                android:layout_marginBottom="10dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

    </com.google.android.material.navigation.NavigationView>


</androidx.drawerlayout.widget.DrawerLayout>

Java 文件


public class MainActivity extends AppCompatActivity {
    ListView listView;
    String[] packageName;
    String[] appName ;
    Drawable[] img ;
    String[] newAppName;
    String[] newPackageName;
    Drawable[] newImg;
  


    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main2);


         installedApps();

        Mylistadapter adapter = new Mylistadapter(this,newAppName,newImg);

        listView=findViewById(R.id.listView);
        listView.setAdapter(adapter);
        listView.setonItemClickListener((parent,view,position,id) -> {
            String item = (String) listView.getItemAtPosition(position);
            try {
                Thread.sleep(1000);
            }
            catch (Exception e) {}


            Intent intent = getPackageManager().getLaunchIntentForPackage(newPackageName[position]);
            intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK );



            ActivityOptions ao = ActivityOptions.makeBasic();
            Rect rect = new Rect(0,100);
            ActivityOptions bounds = ao.setLaunchBounds(rect);
            startActivity(intent,bounds.toBundle());
            finish();
            Toast.makeText(getApplicationContext(),"You selected : " + item,Toast.LENGTH_SHORT).show();
        });





        }




    @SuppressLint("LongLogTag")
    private void installedApps() {
        @SuppressLint("QueryPermissionsNeeded") List<PackageInfo> packageInfoList = getPackageManager().getInstalledPackages(0);

        appName= new String[packageInfoList.size()];
        packageName = new String[packageInfoList.size()];
        img = new Drawable[packageInfoList.size()];

        for (int i=0; i<packageInfoList.size(); i++){

            PackageInfo packageInfo = packageInfoList.get(i);
            if((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYstem)==0){


               appName [i]= packageInfo.applicationInfo.loadLabel(getPackageManager()).toString();
                packageName[i] = packageInfo.packageName;

                  try {

                        img[i] = getApplicationContext().getPackageManager().getApplicationIcon(packageName[i]);

                    } catch (PackageManager.NameNotFoundException ne) {


                }


            }
        }

        NewAppName();
        NewPackageName();
        NewImg();

        Log.i("1AppName + PackageName + icon",Arrays.toString(newAppName) +"---"+ Arrays.toString(newPackageName) +"---"+ Arrays.toString(newImg));

    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)