如何在不使用库的情况下在状态、聚焦和正常状态下应用 TextInputLayout 的自定义形状

Abd*_*dir 1 android widget android-textinputlayout material-components material-components-android

我想设计一个自定义圆角 TextInputLayout 正如我展示的活动 TextInputLayout 的示例图像在此输入图像描述以下

我的 xml 代码是

<com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/mobile_number"
                android:inputType="number"
                android:fontFamily="@font/montserrat_regular"
                android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

它给我一个默认的 TextInputLayout。我怎样才能得到我的观点。请帮助我。样式声明中出现错误。 样式声明错误

Gab*_*tti 7

只需使用Widget.MaterialComponents.TextInputLayout.OutlinedBox样式并应用自定义形状:

    <com.google.android.material.textfield.TextInputLayout
        style="@style/OutlinedRoundedBox"
        ...>
Run Code Online (Sandbox Code Playgroud)

和:

 <style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="shapeAppearanceOverlay">
      @style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded
    </item>
  </style>

  <style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">32dp</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述