我在应用程序中的某个地方有一个微调框,需要在每个项目之间提供边框和分隔线,我做到了以下一切似乎都很好,但是当我单击它时,在下拉列表中没有该边框的迹象现在,我需要下拉列表周围的边框,这是我所做的:
我希望我的微调框看起来像这样:
但是看起来像这样
。
这里是布局活动中的微调器:
<Spinner
android:id="@+id/cities_spinner"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginTop="156dp"
android:layout_marginEnd="20dp"
android:background="@drawable/spinner_border"
android:entries="@array/cities"
android:popupElevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.487"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</Spinner>
这是微调框:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="40dp" />
<stroke
android:color="#707070"
android:width="1dp" />
</shape>
这是每个微调器项目的文本视图:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:textColor="#fefcfe"
android:padding="10dp"
android:textSize="18dp"
android:background="@drawable/spinner_item_devider" />
这是spinner_item_devider:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#707070"/>
</shape>
</item>
<item android:bottom="1.5dp">
<shape android:shape="rectangle">
<solid android:color="@color/white"/>
</shape>
</item>
</layer-list>
这是用于设置适配器的一段Java代码:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.cities,R.layout.spinner_text_view);
adapter.setDropDownViewResource(R.layout.spinner_text_view);
cities.setAdapter(adapter);
而且这也没有在适配器中显示任何内容,不知道为什么,所以可以寻求帮助。
答案 0 :(得分:0)
类似这样的东西
<Spinner
android:id="@+id/cities_spinner"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
...
android:dropDownVerticalOffset="40dp"
android:background="@drawable/spinner_border_top"
android:popupBackground="@drawable/spinner_border_bottom"
...
>
</Spinner>
spinner_border_top
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<stroke
android:color="#707070"
android:width="1dp" />
</shape>
spinner_border_bottom
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"/>
<stroke
android:color="#707070"
android:width="1dp" />
</shape>
spinner_text_view_1
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:padding="10dp"
android:textSize="18dp"
/>
spinner_text_view
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:padding="10dp"
android:background="@drawable/spinner_item_divider"
android:textSize="18dp"
/>
spinner_item_divider
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0dp"
android:left="-6dp"
android:right="-6dp"
android:bottom="-6dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#707070"/>
</shape>
</item>
</layer-list>
适配器设置
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.country_data, R.layout.spinner_text_view_1);
adapter.setDropDownViewResource(R.layout.spinner_text_view);
cities.setAdapter(adapter);