Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

java - Android Spinner - How to make dropdown view transparent?

I have a custom spinner dropdown xml file in /res/layout/:

spinner_view_dropdown.xml:

<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_item_dropdown"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
style="@style/spinner_item_dropdown" />

I'm setting the spinner dropdown via java:

// "Spinner", aka breadcrumbs
    Spinner spin = (Spinner) findViewById(R.id.breadcrumb_dropdown);

    ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.breadcrumb, R.layout.spinner_view);

    adapter.setDropDownViewResource(R.layout.spinner_view_dropdown);

    spin.setAdapter(adapter);
    // /"Spinner"

Unfortunately, a white background still exists on the spinner popup regardless if I set the background to transparent.

How do I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can override the style for the dropdown, and the dropdown item by using a Theme in your app that inherits from one of the Android themes, then override the

android:dropDownSpinnerStyle, or android:spinnerDropDownItemStyle, and even the android:dropDownListViewStyle attribute of the theme, pointing to your own custom style instead of the Android style that is defined in their theme. I created a fully customized spinner this way, with a transparent button AND dropdown. I even got rid of the dropdown list dividers, and set my own spacing for the dropdown items when I built the tablet app for Fandango (take a look at the sort movies spinner on the main page of the app).

Everything in Android is customizable, you just have to know where to look. ;-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...