【问题标题】:How to manage Base activity with navigation drawer [closed]如何使用导航抽屉管理基本活动 [关闭]
【发布时间】:2016-11-12 09:34:03
【问题描述】:

在我的导航抽屉中,我不想使用活动以及如何以正确的方式使用片段。

【问题讨论】:

    标签: android performance android-layout android-activity fragment


    【解决方案1】:
    Impment FragmentDrawer.FragmentDrawerListener on your MainActivityClass. than write belowed code for as many fragment you want to replace in your application.     
    
              implements FragmentDrawer.FragmentDrawerListener
         activity_main.xml
    <android.support.v4.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">
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <LinearLayout
                android:id="@+id/container_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <include
                    android:id="@+id/toolbar"
                    layout="@layout/toolbar" />
            </LinearLayout>
    
            <FrameLayout
                android:id="@+id/container_body"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
    
    
        </LinearLayout>
    
    
        <fragment
            android:id="@+id/fragment_navigation_drawer"
            android:name="com.archi.intrisfeed.slidemenu.FragmentDrawer"
            android:layout_width="@dimen/nav_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_navigation_drawer"
            tools:layout="@layout/fragment_navigation_drawer" />
    
    </android.support.v4.widget.DrawerLayout>
    
    
    
    
         @Override
            public void onDrawerItemSelected(View view, int position) {
                displayView(position);
            }
    
    
         private void displayView(int position) {
                Fragment fragment = null;
                String title = getString(R.string.app_name);
                switch (String.valueOf(position)) {
                    case "0":
                        fragment = new HomeFragment();
                        break;
                    case "1":
                        fragment = new BrowseFragment();
                        break;
            default:
                        break;
                }
         if (fragment != null) {
                    FragmentManager fragmentManager = getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.container_body, fragment);
                    fragmentTransaction.commit();
    
                    // set the toolbar title
                    getSupportActionBar().setTitle(title);
    
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      相关资源
      最近更新 更多