我正在解释我的问题。首先,我想让你知道我是编码的初学者;)我目前正在创建一个计算应用程序。该应用程序功能齐全,无错误。我现在想通过添加文本来优化主屏幕(activity_main.xml)。在同一个主屏幕(activity_main.xml)中,我添加了一个DrawerLayout。但是,我已经被困了好几天了。
当TextView被添加到这个Drawerlayout时,我遇到两个问题(取决于代码中textview的位置):文本适用于所有片段,而它应该只应用于activity_main.xml,或者TextView是根本没有显示。
我想就我的问题发表意见,同时找到解决方案;)
这是我的问题的一个例子:
提前谢谢你的回答!
<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/activity_main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context="fr.mathieuch.aide_ventil2.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"/>
<!-- 1 | MainActivity RootView -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ToolBarStyle"/>
<!-- FrameLayout for our fragments -->
<FrameLayout
android:id="@+id/activity_main_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<!-- 2 | NavigationView -->
<android.support.design.widget.NavigationView
android:id="@+id/activity_main_nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/activity_main_nav_header"
app:menu="@menu/activity_main_menu_drawer" />
</android.support.v4.widget.DrawerLayout>
您应该将白色背景添加到片段的xml根目录中。并检查。