1

我正在尝试创建一个与 Google 照片应用程序中的工具栏具有相似样式的搜索栏 - 即用阴影四舍五入。

我们使用 Material 库中的 TextInputLayout 作为片段的唯一子元素(它在父片段的顶部膨胀)。

以下是我目前所拥有的(一旦我可以购买海拔高度,我就有一个可用作背景的可绘制对象,为了清楚起见,我省略了它)

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments.SearchFragment">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/searchTextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/searchTextInputEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:paddingStart="24dp"
                    android:paddingEnd="24dp"
                    android:background="#ffffff"
                    android:elevation="20dp"
                    android:drawableStart="@drawable/ic_menu_black_24dp"
                    android:hint="Search" />
        </com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--android:background="@drawable/searchbar_rounded"-->

我在这里遗漏了一些明显的东西,还是这是 TextInputLayout 的限制?

4

1 回答 1

3

将 textView 放在 cardView 里面,它肯定会产生阴影 cardView 的例子

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="6dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="4dp"
    card_view:cardCornerRadius="3dp">
于 2019-04-25T15:40:58.250 回答