【发布时间】:2022-01-14 00:43:54
【问题描述】:
【问题讨论】:
-
添加您的 xml 文件
标签: android android-edittext android-spinner android-xml
【问题讨论】:
标签: android android-edittext android-spinner android-xml
好吧,您可以使用具有水平方向的LinearLayout 并为圆形边框创建自定义可绘制对象。
首先,您需要通过创建一个新的Drawable resource 文件来绘制圆角边框。
在您的res/drawables 文件夹中创建rounded_border.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="2dp" android:color="#2E2E2E" />
</shape>
</item>
</selector>
然后,您可以将LinearLayout 添加到您的布局中,如下所示。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@drawable/rounded_border"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@null"
android:paddingHorizontal="16dp"
android:text="(504) 596-3245"
android:layout_weight="2"/>
<View
android:layout_width="2dp"
android:background="#2E2E2E"
android:layout_height="match_parent"/>
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
tools:listitem="@layout/spinner_item_text"
android:layout_weight="1"/>
</LinearLayout>
rounded_border.xml 自定义边框宽度、颜色和半径。【讨论】:
可以参考这个库演示:https://github.com/z2wenfa/SpinnerEditText
可以直接使用lib
dependencies {
compile 'com.github.z2wenfa:SpinnerEditText:1.0.1'
}
【讨论】: