android – 当导航抽屉打开时从工具栏中删除阴影 – Material Design支持库

前端之家收集整理的这篇文章主要介绍了android – 当导航抽屉打开时从工具栏中删除阴影 – Material Design支持库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在将Material Design实现到我的带有导航抽屉的应用程序中.在Nav的所有不同实现中.带材料设计的抽屉和工具栏( see this post);我选择让应用程序感觉类似于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" />@H_404_11@ 
 

值得注意的部分是< FrameLayout>其ID为“容器”是我的所有碎片充气的地方,其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>@H_404_11@ 
 

我创建了一个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>@H_404_11@ 
 

最后,在我的Activity的onCreate()中,我在toolbar.xml上设置了setContentView():

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.toolbar);
    // Rest of code here....@H_404_11@
原文链接:https://www.f2er.com/android/316466.html

猜你在找的Android相关文章