如何使AlertDialog中EditText上的黑线变小



这是警报对话框

我正在使用EditText的自定义xml文件来更改其外观。我尝试过设置布局边距、填充,并将其设置为自定义宽度,但没有任何更改。

这是editText的xml:

<EditText xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myEditTextId"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:gravity="center_horizontal"
android:inputType="textNoSuggestions"
android:textCursorDrawable="@drawable/dark_cursor"
tools:ignore="Autofill,LabelFor" />

尝试创建自定义绘图并将其设置为EditText 的背景

类似:

可提取/custom_bg.xml

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="2dp"
android:shape="rectangle">
<stroke android:width="3dp" android:color="#000000"/>

<EditText android:background="@drawable/custom_bg"/>

使UI更加灵活的简单解决方案。首先制作你的Edittextbackground="@null"。然后为你的Edittext画一条黑色下划线。在这里,您可以通过增加或减少黑线的高度值来增加或减少其厚度,该值当前为2px。你可以通过增加或减少它的开始和结束边距来使它变短或变长。您也可以调整EditText的大小。你现在可以做的一切与边距,填充,自定义高度,自定义宽度等

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:background="@null"
android:hint="Your textview"/>
<View
android:id="@+id/divider1"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"/>
</LinearLayout>

最新更新