Fla*_*ash 7 android material-design
我正在将Material Design应用到我的带有导航抽屉的应用程序中.在Nav的所有不同实现中.带材料设计的抽屉和工具栏(见本文); 我选择让应用程序感觉类似于ICS/Halo设计,并将Nav Drawer滑出工具栏.问题是当导航抽屉打开时,工具栏会像活动的其余部分一样变暗.如何防止工具栏变暗?如果你在我上面链接的帖子中看到图像,我在#6,3或5之后,但我现在看起来更像#9.
示例(来自上面的帖子):
我在追求什么(工具栏上没有阴影):

我目前得到的(导航抽屉打开时工具栏变暗):

这是我的主要活动的XML的代码:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.funkhaus.navdrawer.app.MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar; Added for Material Design -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
</FrameLayout>
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:name="com.funkhaus.brewwerks.NavigationDrawerFragment" />
Run Code Online (Sandbox Code Playgroud)
值得注意的部分是<FrameLayout>其ID是'container'我的所有碎片都被充气的地方,并且它marginTop被设置为工具栏的高度,因此其内容将低于工具栏.类似地,导航抽屉片段也marginTop设置为工具栏的高度,因此它在其下方滑出.
感谢@alanv我解决了我的问题.
我上面的帖子显示了我的activity_main.xml代码; 我将其简化为此,删除工具栏视图并删除marginTop格式:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.funkhaus.navdrawer.app.MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:name="com.funkhaus.brewwerks.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我创建了一个toolbar.xml,我现在在我的主Activity中setContentView()<include>就是activity_main.xml上面的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar; Added for Material Design -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<include android:id="@+id/drawer_layout" layout="@layout/activity_main" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
最后,在我的活动中onCreate()我setContentView()对toolbar.xml:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toolbar);
// Rest of code here....
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6118 次 |
| 最近记录: |