gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:23 24 4
gpt4 key购买 nike

我正在将 Material Design 应用到我的带有抽屉导航的应用中。在导航的所有不同实现中。具有 Material Design 的抽屉和工具栏(see this post);我选择让应用程序感觉类似于 ICS/Halo 设计,并将抽屉导航滑出工具栏下方。问题是当抽屉导航打开时,工具栏会像其他 Activity 一样随着阴影变暗。我如何防止工具栏变暗?如果您看到我上面链接的帖子中的图片,我在 #6、3 或 5 之后,但我现在看起来更像 #9。

示例(来自上面的帖子):

我想要的(工具栏上没有阴影):

enter image description here

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

enter image description here

这是我主要 Activity 的 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" />

值得注意的部分是 <FrameLayout>其编号为'container'是我所有 fragment 膨胀的地方,它的 marginTop设置为工具栏的高度,因此其内容将低于工具栏。同样,Navigation Drawer fragment 也有它的 marginTop。设置为工具栏的高度,以便它从下方滑出。

最佳答案

感谢@alanv 我解决了我的问题。

我上面的帖子显示了我的 activity_main.xml代码;我将其简化为这样,删除了工具栏 View 并删除了 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>

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

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

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

setContentView(R.layout.toolbar);
// Rest of code here....

关于android - 打开抽屉导航时从工具栏中移除阴影 - Material Design 支持库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26663664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com