我正拼命地寻求帮助。因此,我一直在遵循本教程系列,这绝对是很棒的,但是与Bottom Navigation
在视频中使用像他一样的方式相比,我在使用带有片段的“导航抽屉”。
当我选择HomeFragment
内NavigationDrawer
,布局加载,但一切被推向下跌破Toolbar
。现在,该工具栏已完全可以用作汉堡包,并且确实有更多选项菜单图标,但对于白色也看不见,因此这更多是设计问题。
另外,关于Toolbar's
样式,是的,我故意使它透明,以使完成的UI看起来像下面的“预期输出”图像。
预计输出-这是相同的布局看起来像HomeActivity
在反对HomeFragment
。
以下是我的的代码,该代码HomeActivity
嵌套FrameLayout
的Fragments
。
<?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>
我已经像正常一样Toolbar
在HomeActivity
类中声明并启动了,当HomeActivity
显示时Toolbar
确实存在,这使我怀疑是否必须在HomeFragment
类中再次声明它?如果是这样,您将如何去做?
如果其他布局或类要求任何其他代码,请询问。任何帮助都感激不尽!
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 FrameLayout
from 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] 删除。
我来说两句