2016-09-18 6 views
0

ich das Aussehen der Spinner, so etwas ändern möchten - enter image description hereändern Aussehen des Spinners

Derzeit sieht es so aus -

enter image description here

Welche Änderungen muss ich machen ?

Hier ist mein xml-Code -

<Spinner 
    android:id="@+id/country_spinner" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/textview5" 
    android:layout_marginEnd="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginTop="24dp" 
    android:spinnerMode="dialog" 
    android:prompt="@string/choose_your_country" 
    /> 

In Haupttätigkeit -

final ArrayList<Country> countries = addAllCountries(); 
    countrySpinner = (Spinner) findViewById(R.id.country_spinner); 
    CountrySpinnerAdapter adapter = new CountrySpinnerAdapter(MainActivity.this, countries); 
    countrySpinner.setAdapter(adapter); 

Antwort

0

diese Abhängigkeiten hinzufügen in build.gradle Datei

compile 'com.github.rey5137:material:1.2.2' 

In Xml dieser Code zu schreiben.

<com.rey.material.widget.Spinner 
        android:id="@+id/spinner_label" 
        style="@style/LightSpinner" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:minWidth="128dp" 
        android:padding="8dp" 
        app:spn_label="Spinner with arrow" /> 

In Java schreiben Sie diesen Code.

Spinner spn_label = (Spinner) findViewById(R.id.spinner_label); 
String[] items = new String[20]; 
    for (int i = 0; i < items.length; i++) { 
      items[i] = "Item " + String.valueOf(i + 1); 
     } 
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.row_span, items); 
spn_label.setAdapter(adapter); 

erstellen row_span.xml in Ihrem Layout-Ordner.

<?xml version="1.0" encoding="utf-8"?> 
<com.rey.material.widget.TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/row_spn_tv" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:gravity="center_vertical" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:textDirection="locale" 
    style="@style/LightSpinner"/> 

Ausgang:

enter image description here

Für weitere Einzelheiten besuchen Sie meine diese Antwort: Android Spinner showing transparent screen with distortion of data,but items are selectable

und für Github Bibliothek Besuch dieser: https://github.com/rey5137/material#donation

Verwandte Themen