簡體   English   中英

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

[英]How can I make a toolbar stay on the screen?

我有一個帶有一些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>

嘗試使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM