Java (安卓)我的简单导航抽屉碎片不';看不到错误图片
我的导航系统出了什么问题。我认为我的activity main.xml中存在问题。在我的导航抽屉里有一个发送的片段,如果你点击发送,它将显示一个使用此代码的文本视图“测试” SentFragment.javaJava (安卓)我的简单导航抽屉碎片不';看不到错误图片,java,android,android-layout,android-fragments,navigation-drawer,Java,Android,Android Layout,Android Fragments,Navigation Drawer,我的导航系统出了什么问题。我认为我的activity main.xml中存在问题。在我的导航抽屉里有一个发送的片段,如果你点击发送,它将显示一个使用此代码的文本视图“测试” SentFragment.java public class SentFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
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;
}
}
在得到这个布局时,我使用了这个代码
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();
代码正在运行,没有错误。但是如果要运行它,请选择“发送到”导航抽屉。它不打算打开其他页面,然后测试文本视图显示在我的listview上。
我想是因为我的活动_main.xml。我的框架布局或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)。现在它是透明的。为布局提供背景色(白色-#FFFFFF)。现在它是透明的。为什么您的containerView在AppBarLayout中?你也在它下面使用ViewPager!我可以知道我的xml中代码的正确位置吗@Harry为什么你的containerView在AppBarLayout中?你也在它下面使用ViewPager!我可以知道我的xml中代码的正确位置吗@Harry我不这么认为,它只能显示白色背景,但标签在那里。我不这么认为,它只能显示白色背景,但标签在那里。