【发布时间】:2016-12-12 19:21:55
【问题描述】:
我不熟悉抽屉布局和片段的使用。
我在使用DrawerLayout 创建活动时使用了tutorial。
它在getActionBar() 上给了我一个空指针,所以我将a toolbar 添加到活动主目录并改用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 中,但这不起作用。
为什么我的工具栏会填满整个屏幕?
【问题讨论】:
-
这个有什么价值?:android:layout_height="?attr/actionBarSize"
-
那是 56dp。如果我删除它并乱扔布局_height =“56dp”,它仍然是全屏。
-
将您的主题属性移动到高度属性之前(可能在那里设置高度)。
标签: android toolbar drawerlayout