带有EditText的工具栏。如何制作可折叠?

问题描述 投票:0回答:1

我正在尝试使用EditText准备工具栏。使用不同的来源,我可以创建它:

enter image description here

但是,我无法在向后箭头旁边的工具栏中添加标题,无法更改向后箭头本身的颜色,并且最后一个固定且无法折叠的工具栏已通过某种方式固定。这是我的活动xml

<androidx.coordinatorlayout.widget.CoordinatorLayout 
    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="wrap_content"
    android:fitsSystemWindows="true"
    tools:context=".CreateActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                app:layout_collapseMode="parallax" />
        </com.google.android.material.appbar.CollapsingToolbarLayout>

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="parallax"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingStart="32dp"
                android:paddingLeft="32dp"
                android:paddingTop="32dp"
                android:paddingEnd="32dp"
                android:paddingRight="32dp"
                android:paddingBottom="56dp">

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/lNameLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp">

                    <EditText
                        android:id="@+id/title_et"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:hint="Title"
                        android:importantForAutofill="no"
                        android:inputType="text" />
                </com.google.android.material.textfield.TextInputLayout>

            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是我的Activity的Kotlin课:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_create)

        val toolbar: Toolbar = findViewById(R.id.toolbar)
        toolbar.title = "Create Note"
        setSupportActionBar(toolbar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar!!.setHomeButtonEnabled(true)

        val ctl = findViewById<CollapsingToolbarLayout>(R.id.collapsing_toolbar)
        ctl.title = "Best Coupons Deals"
    }
}

我错过了什么?

android xml kotlin toolbar
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.