导航抽屉片段影响工具栏的样式和位置

Android的DevBro

我正拼命地寻求帮助。因此,我一直在遵循教程系列,这绝对是很棒的,但是与Bottom Navigation在视频中使用像他一样的方式相比,我在使用带有片段的“导航抽屉”。

当我选择HomeFragmentNavigationDrawer,布局加载,但一切被推向下跌破Toolbar现在,该工具栏已完全可以用作汉堡包,并且确实有更多选项菜单图标,但对于白色也看不见,因此这更多是设计问题。

另外,关于Toolbar's样式,是的,我故意使它透明,以使完成的UI看起来像下面的“预期输出”图像。

预计输出-这是相同的布局看起来像HomeActivity在反对HomeFragment

以下是我的的代码,该代码HomeActivity嵌套FrameLayoutFragments

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.michaeldybek.plasticoceansapp.HomeActivity">

    <FrameLayout
        android:id="@+id/mainContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@id/toolbar"
        app:layout_constraintTop_toBottomOf="@id/toolbar">
    </FrameLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@null"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

我已经像正常一样ToolbarHomeActivity类中声明并启动了,当HomeActivity显示Toolbar确实存在,这使我怀疑是否必须在HomeFragment类中再次声明它如果是这样,您将如何去做?

如果其他布局或类要求任何其他代码,请询问。任何帮助都感激不尽!

Android的DevBro

So after a week of solid research, I have finally manage to come up with a solution which bypassed this issue!

I ended up removing the Toolbar and FrameLayoutfrom HomeActivity, and instead created a new layout resource file and called it "app_bar.xml", which contained the following code:

<RelativeLayout
    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.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".core.MainActivity">

        <FrameLayout
            android:id="@+id/mainContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:elevation="0dp"
        android:stateListAnimator="@null">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Light"/>

    </android.support.design.widget.AppBarLayout>

</RelativeLayout>

I then followed by including the app_bar in the HomeActivity layout using the include tag (HomeActivity also houses the NavigationView nested within a DrawerLayout).

I hope this helps whomever comes across this question. If you have any further queries, ask away!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

片段和导航抽屉的不同工具栏

使用导航抽屉模板更改片段中的工具栏

Vuetify 同时设置工具栏和导航抽屉

将Android导航组件与片段内的单个活动,布局抽屉和工具栏一起使用

工具栏下方的导航抽屉

基本ConstraintLayout(工具栏,片段容器和底部导航)

使用导航抽屉或工具栏菜单对片段过渡进行动画处理

导航组件:如何在每个片段中设置带有工具栏的抽屉

片段工具栏中的向上导航

使用片段/工具栏返回导航

将除主片段以外的所有片段添加回工具栏的按钮,以打开导航抽屉

在操作栏/工具栏上展开导航抽屉

Android支持库23.2-导航抽屉和/或工具栏

在抽屉和导航视图中重用工具栏布局

带有选项卡的导航抽屉和工具栏

更改导航抽屉和工具栏的默认字体颜色

Vuetify 2个工具栏和1个导航抽屉,其中1个工具栏位于导航抽屉上方

如何使我的片段适合我的工具栏和底部导航栏之间并使它仍可滚动?

使用导航抽屉滚动Android工具栏

导航抽屉布局工具栏中的标题未更改

如何将导航抽屉放在工具栏下方?

导航抽屉未在工具栏上绘制

工具栏隐藏在导航抽屉的后面

折叠工具栏和片段

片段中的片段/工具栏显示在错误的位置

片段内容重叠工具栏和底部导航视图

使用工具栏中的按钮在片段之间导航

使用活动的工具栏从片段向上导航

在片段更改期间如何存储和恢复折叠工具栏的滚动位置?