如何使工具栏停留在屏幕上?

时间:2019-08-14 11:56:09

标签: java android xml toolbar

我有一个带有一些TextViews和EditTexts的屏幕,以及一个工具栏。 当我单击编辑文本以输入一些文本时,工具栏消失了 即使引入文字(或滚动,如果引入滚动视图),如何始终使工具栏始终显示在屏幕上

 <androidx.constraintlayout.widget.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:id="@+id/createTreasureScreen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".view.fragment.CreateTreasureFragment">

        <Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/toolbarTreasureHeight"
                android:background="@color/Blue"
                android:elevation="@dimen/loginToolbarElevation"
                android:title="@string/page_title"
                android:titleMarginStart="@dimen/toolbarMarginStart"
                android:titleTextAppearance="@style/toolbarStyle"
                android:titleTextColor="@color/White"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@id/parent"
                app:titleEnabled="false" />

    </androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

尝试使用FrameLayout。这样可以使您的Toolbar始终位于其他视图的顶部,并且在添加ScrollView时可见。

<FrameLayout 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">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/createTreasureScreen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".view.fragment.CreateTreasureFragment">

    <!--Add your other views here-->

    </androidx.constraintlayout.widget.ConstraintLayout>

    <Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/toolbarTreasureHeight"
        android:background="@color/Blue"
        android:elevation="@dimen/loginToolbarElevation"
        android:title="@string/page_title"
        android:titleMarginStart="@dimen/toolbarMarginStart"
        android:titleTextAppearance="@style/toolbarStyle"
        android:titleTextColor="@color/White"
        android:layout_gravity="top"
        app:titleEnabled="false" />

</FrameLayout>
相关问题