我对抽屉布局和片段的使用还不熟悉。
我使用了创建带有
现在它看起来像是工具栏填满整个屏幕,因为标题位于屏幕中央,而工具栏的背景也覆盖整个屏幕。这是xml代码:
我尝试将layout_height替换为56dp,也尝试创建一个带有工具栏的单独布局文件并将其包含到此xml中,但没有成功。
为什么我的工具栏占据整个屏幕?
我使用了创建带有
DrawerLayout
的活动的tutorial。它在getActionBar()
上给了我一个空指针异常,因此我在活动主界面中添加了工具栏并改用getSupportActionBar()
。现在它看起来像是工具栏填满整个屏幕,因为标题位于屏幕中央,而工具栏的背景也覆盖整个屏幕。这是xml代码:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
我尝试将layout_height替换为56dp,也尝试创建一个带有工具栏的单独布局文件并将其包含到此xml中,但没有成功。
为什么我的工具栏占据整个屏幕?