0

I use AppCompat theme. After migrating to Android Studio 1.1, background color has turned from transparent to gray, and worse, spinners are shown with a white background; since text color also is white, items in the list can't be read.

Is there a way to get the original appearance, ie transparent background, or, at least, where must I set the spinner background color to transparent?

Edited: I have created a basic test app with 2 spinners on a screen. The first spinner is declared inside the activity layout, the second one comes from a separate layout and is inflated inside the activity layout. The two spinner have the same configuration, but they are displayed differently.

[link]http://s15.postimg.org/4y5nwourv/Screenshot_2015_03_12_01_23_14.png

[link]http://s8.postimg.org/ti8x5b4w5/Screenshot_2015_03_12_01_23_26.png

I would like to have the first spinner (the one from the activity layout) to be displayed like the one that is from the inflated layout.

Thanks

Edited: The test app code

Main activity

    public class MainActivity extends Activity {

        private Spinner spinnerLanguagesLayout, spinnerLanguagesInflated;
        public List<String> languages = new ArrayList<String>();
        private ArrayAdapter<String> adapterLayoutLanguages, adapterInflateLanguages;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            init();
        }
        public void init() {
            LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE);
            LinearLayout linearLayoutInflate = (LinearLayout) this.findViewById(R.id.linearLayoutInflate);
            LinearLayout linearLayoutSpinnerLanguage = (LinearLayout)  inflater.inflate(R.layout.specific_spinner_language, null, false);
            linearLayoutInflate.addView(linearLayoutSpinnerLanguage);
            linearLayoutSpinnerLanguage.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
            languages.add("english");
            languages.add("chinese");
            initSpinnerLayout();
            initSpinnerInflate();
        }
        public void initSpinnerLayout() {
            spinnerLanguagesLayout = (Spinner) this.findViewById(R.id.spinnerLanguagesLayout);
            adapterLayoutLanguages = new LanguagesListAdapter();
            spinnerLanguagesLayout.setAdapter(adapterLayoutLanguages);
        }
        public void initSpinnerInflate() {
            spinnerLanguagesInflated = (Spinner) this.findViewById(R.id.spinnerLanguagesInflated);

            adapterInflateLanguages = new LanguagesListAdapter();
            spinnerLanguagesInflated.setAdapter(adapterInflateLanguages);
        }
        public class LanguagesListAdapter extends ArrayAdapter<String> {
            public LanguagesListAdapter() {
                super (getApplicationContext(), R.layout.layout_spinner, languages);
            }
            @Override
            public View getView(int position, View view, ViewGroup parent) {
                if (view == null)
                {
                    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    view = inflater.inflate(R.layout.layout_spinner, parent, false);
                }
                final TextView textViewLanguage = (TextView) view.findViewById(R.id.textView);
                textViewLanguage.setText(languages.get(position));

                return view;
            }
            @Override
            public View getDropDownView(int position, View convertView, ViewGroup parent)
            {   // This view starts when we click the spinner.
                View row = convertView;
                if(row == null)
                {
                    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = inflater.inflate(R.layout.layout_spinner, parent, false);
                }
                final TextView textViewLanguage = (TextView) row.findViewById(R.id.textView);
                textViewLanguage.setText(languages.get(position));
                return row;
            }
        }
    }

Main activity layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fluentdroid="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Spinner from activity layout"
            android:id="@+id/textView2"
            android:layout_gravity="center_horizontal" />

        <Spinner
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerLanguagesLayout"
            style="@style/Base.TextAppearance.AppCompat.Large" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutInflate"
        android:layout_weight="1"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"></LinearLayout>

</LinearLayout>

Inflated spinner layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Spinner from inflated layout"
        android:id="@+id/textView3" />

    <Spinner
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/spinnerLanguagesInflated"
        style="@style/Base.TextAppearance.AppCompat.Large"/>

</LinearLayout>

Spinner item layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:gravity="center_horizontal"
        style="@style/Base.TextAppearance.AppCompat.Large" />

</LinearLayout>
poolpie
  • 1
  • 2
  • Is maybe visible only in preview, test in emulator or better test in read device. I had the same issue yesterday when I updated my Studio but it works fine in real device – Apurva Mar 08 '15 at 16:55
  • Change theme to Light.DarkActionBar. – IshRoid Mar 08 '15 at 16:57
  • @Apurva: I have the issue with a real device – poolpie Mar 09 '15 at 06:43
  • @Ishrat: Same issue with Light.DarkActionBar theme. – poolpie Mar 09 '15 at 06:44
  • Could you please update your question by screenshot? Or try http://stackoverflow.com/a/27747760/1881611 – IshRoid Mar 09 '15 at 07:02
  • @ishrat: Screenshot: [link]http://s17.postimg.org/hk3tepqin/Screenshot_2015_03_09_16_18_38.png – poolpie Mar 09 '15 at 09:25
  • I found another spinner that displays fine in my app. I have not yet found config differences between the two spinners or layout... I guess I will have to create a style for the layout where the spinner is not well displayed. Thanks for your help. – poolpie Mar 09 '15 at 10:00
  • I found a solution here [apply theme to application context][1] [1]: http://stackoverflow.com/questions/2118251/theme-style-is-not-applied-when-inflater-used-with-applicationcontext – poolpie Mar 12 '15 at 08:59

0 Answers0