如何在 Android Studio 中围绕编辑文本创建矩形框
How to create rectangular box around edittext in Android Studio
我想创造一个有吸引力的UI。我想在编辑文本周围创建一个矩形框。我怎样才能做到?
创建一个形状为矩形的可绘制对象并应用背景来编辑文本
<shape android:shape="rectangle">
<stroke android:width="1dip" android:color="#4e555f" />
</shape>
<EditText
android:id="@+id/sign_in_mobile_no"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="drawable name"/>
只需使用带有 OutlinedBox 样式的标准 TextInputLayout
:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TEXT"/>
</com.google.android.material.textfield.TextInputLayout>
您可以使用 boxStrokeWidth
和 boxStrokeColor
来更改宽度和颜色。
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeColor="@color/xxxx"
app:boxStrokeWidth="2dp"
我想创造一个有吸引力的UI。我想在编辑文本周围创建一个矩形框。我怎样才能做到?
创建一个形状为矩形的可绘制对象并应用背景来编辑文本
<shape android:shape="rectangle">
<stroke android:width="1dip" android:color="#4e555f" />
</shape>
<EditText
android:id="@+id/sign_in_mobile_no"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="drawable name"/>
只需使用带有 OutlinedBox 样式的标准 TextInputLayout
:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TEXT"/>
</com.google.android.material.textfield.TextInputLayout>
您可以使用 boxStrokeWidth
和 boxStrokeColor
来更改宽度和颜色。
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeColor="@color/xxxx"
app:boxStrokeWidth="2dp"