(Android版)我简单的导航抽屉片段不工作,看到的错误画面 [英] (Android) My simple navigation drawer fragment doesn't work-see the error picture
问题描述
发生了什么事我的导航。我认为theres一个问题,我的活动main.xml中。在我的抽屉式导航栏那里有一个发送fragtment如果你点击发送,它会显示一个TextView测试使用这种code。
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
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;
}
}
和在得到这个布局我用这code。
and in getting the layout of this i am using this code.
Main.java
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();
在code运行时没有错误,但如果我要运行它,并选择在导航抽屉里发送。它不打算到其他页面,那么测试的TextView被显示在列表视图我。
我想是因为我的activity_main.xml中的。是我的FrameLayout或XML是否正确?
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中
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>
推荐答案
使背景颜色(白色 - #FFFFFF),以sent_layout。现在它是透明的。
Give background colour (White- #FFFFFF) to sent_layout. Right now its transparent.
这篇关于(Android版)我简单的导航抽屉片段不工作,看到的错误画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!