简体   繁体   English

Android Spinner的样式没有改变

[英]Android spinner not changing in style

So I have the spinner working and it works fine, but I can't change any of the styles except the background color in the activity_main.xml 因此,我可以使用微调器,并且可以正常工作,但是除了activity_main.xml中的背景色,我无法更改任何样式

First one is the simple_spinner_dropdown_item.xml 第一个是simple_spinner_dropdown_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/text1"
          style="?android:attr/spinnerDropDownItemStyle"
          android:layout_width="match_parent"
          android:layout_height="48dp"
          android:background="@color/app_primary"
          android:ellipsize="marquee"
          android:layout_centerVertical="true"
          android:singleLine="true"
          android:textColor="@color/white"
/>

Second one is simple_dropdown_item.xml 第二个是simple_dropdown_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/text1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textColor="@color/white"
          android:background="@color/app_primary"
          android:textSize="20sp"
          android:textStyle="normal"
 />

If you want to customize the dropdown list items you will need to create a new layout file. 如果要自定义下拉列表项,则需要创建一个新的布局文件。 Let's call it spinner_dropdown_item.xml: 我们称它为spinner_dropdown_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:textColor="#aa66cc"/>

Another change in the declaration of the spinner: 微调器声明中的另一个更改:

ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spinner.setAdapter(adapter);

Try this , hope it help 试试这个 ,希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM