我正在尝试自定义物料TextInpuLayout.OutlinedBox
和TextInputEditText
。
我的当前状态如下图所示>>
我想做的是删除提示标签的背景,以免它造成难看的切口。像这样:
或者如果不可能将标签移到输入上方也可以解决问题:
如果使用样式可以做到这一点,那很好,这样我也可以轻松地将其应用于其他文本输入元素。我是android的新手,所以请体谅。
这是样式代码:
<style name="MyTheme" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox"> <item name="android:textSize">14sp</item> <item name="boxCornerRadiusTopStart">@dimen/textInputCornerRadius</item> <item name="boxCornerRadiusTopEnd">@dimen/textInputCornerRadius</item> <item name="boxCornerRadiusBottomStart">@dimen/textInputCornerRadius</item> <item name="boxCornerRadiusBottomEnd">@dimen/textInputCornerRadius</item> <item name="boxBackgroundColor">@color/primaryDarkColorBackground</item> <item name="boxStrokeColor">@color/text_input_box_stroke</item> </style> <style name="EditTextStyle" parent="Widget.AppCompat.EditText"> <item name="android:background">@null</item> <item name="android:paddingStart">30dp</item> </style>
这是我在布局中定义输入的方式:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_layout"
style="@style/MyTheme"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginEnd="48dp"
android:hint="@string/email_or_username"
app:boxBackgroundMode="outline"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.10">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
style="@style/EditTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
我正在尝试自定义材质TextInpuLayout.OutlinedBox和TextInputEditText。我当前的状态就像下面的图像,我要删除的是提示标签的背景,以便...
我认为您无法通过TextInputLayout.OutlinedBox
样式获得它。它不是您要找的东西: