(Android) My simple navigation drawer fragment doe

2019-08-09 09:50发布

what happened to my navigation. i think theres a problem in my activity main.xml . in my navigation drawer theres a sent fragtment like if you click on the sent it will show a textview "Test" using this code.

SentFragment.java

public class SentFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.sent_layout, container,false);
        return view;

    }
}

and in getting the layout of this i am using this code.

Main.java

  mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                mDrawerLayout.closeDrawers();


                if (menuItem.getItemId() == R.id.nav_item_sent) {


                    getSupportFragmentManager().beginTransaction().replace(R.id.containerView,new SentFragment()).commit();
                    Toast.makeText(getApplicationContext(), "Sent!",
                            Toast.LENGTH_SHORT).show();

                }
                if (menuItem.getItemId() == R.id.nav_item_draft) {

                    mFragmentManager = getSupportFragmentManager();
                    FragmentTransaction ft_drafts = mFragmentManager.beginTransaction();
                    ft_drafts.replace(R.id.containerView, new DraftFragment()).commit();

                    Toast.makeText(getApplicationContext(), "Drafts!", Toast.LENGTH_SHORT).show();
                }


                return true;
            }


        });


        android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
        ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name,
                R.string.app_name);

        mDrawerLayout.setDrawerListener(mDrawerToggle);

        mDrawerToggle.syncState();

the code is running there is no error ., but if am going to run it and select the SENT in navigation drawer. it doesnt intent to other page and then the TEST textview is showing on my listview . I think because of my activity_main.xml. is my framelayout or xml correct?

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">


        <android.support.design.widget.CoordinatorLayout android:id="@+id/coordinatorLayout"
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">



            <android.support.design.widget.AppBarLayout

                android:id="@+id/appBarLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <FrameLayout
                    android:id="@+id/containerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
                </FrameLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="fill_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    android:title="Android Testing"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
                <!-- Tab Layout for creating tabs -->
                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/material_blue_grey_800"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="@color/main_color"
                    app:tabMode="fixed"
                    app:tabSelectedTextColor="@color/main_color"
                    app:tabTextColor="@color/white">

                </android.support.design.widget.TabLayout>
                <!-- Helps handing the Fragments for each Tab -->
            </android.support.design.widget.AppBarLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        </android.support.design.widget.CoordinatorLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/shitstuff"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginTop="-24dp"
        app:itemTextColor="@color/black"
        app:menu="@menu/drawermenu"/>

</android.support.v4.widget.DrawerLayout>

enter image description here

1条回答
趁早两清
2楼-- · 2019-08-09 10:00

Give background colour (White- #FFFFFF) to sent_layout. Right now its transparent.

查看更多
登录 后发表回答