【发布时间】:2019-02-20 16:52:33
【问题描述】:
【问题讨论】:
-
编辑了标签
标签: xml android-layout layout material-design android-spinner
【问题讨论】:
标签: xml android-layout layout material-design android-spinner
试试这个代码:
首先创建一个drawable文件
spinner_bg.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="5dp" />
<solid android:color="#F5F5F5"/>
<stroke android:width="3dp"
android:color="#454551"/>
</shape>
</item>
</selector>
现在,在布局文件中使用spinner_bg.xml作为背景,布局文件代码如下:
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#F5F5F5"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginTop="15dp">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="50dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Group"
android:textSize="18sp"
android:background="#F5F5F5"
android:layout_marginLeft="10dp"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginTop="15dp">
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="50dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Literature"
android:textSize="18sp"
android:background="#F5F5F5"
android:layout_marginLeft="10dp"
android:padding="5dp"/>
</RelativeLayout>
</LinearLayout>
这是上面代码的输出:
我希望它对你有用。
【讨论】: