【发布时间】:2015-05-17 16:25:07
【问题描述】:
这是我所有的相关代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("sometitle");
toolbar.inflateMenu(R.menu.menu_main);
setSupportActionBar(toolbar);
样式:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/sunshine_blue</item>
<item name="colorPrimaryDark">@color/sunshine_dark_blue</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="windowActionBar">false</item> <!-- Remove the default action bar -->
<item name="windowNoTitle">true</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Replace the default action bar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:elevation="5dp"
android:background="?attr/colorPrimary" />
<!-- The main content view -->
<fragment 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/fragment"
android:name="com.***.***.***.MainActivityFragment"
tools:layout="@layout/fragment_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
结果如下:
【问题讨论】:
-
可能需要指定固定高度而不是使用
wrap_content? -
如果删除 minheight 和 maxHeight 并使用特定尺寸而不是 wrap_content 会怎样?
-
但是硬编码的尺寸是不好的做法,对吧?
-
这是您仅有的 XML 代码吗?你不是将代码包装在另一个视图中,比如框架布局还是相对布局?
-
不,我是@rogerthatcode .. 顺便说一句,只是为了它,我试了一下硬编码的尺寸,但它在神话中不起作用。
标签: android