Ich benutze das Widget Spinner
mit einem benutzerdefinierten Adapter und benutzerdefinierten Ansichten in spinnerMode
Drop-Down. Mein Problem ist, dass ich den Standardschatten nicht entfernen kann, der das Dropdown von Spinner
wirft. So entfernen Sie den Schatten des Spinner DropDownView
Hier ist der Code innerhalb des Activity
mSpinner = (Spinner)findViewById(R.id.spinner);
setSpinnerData();
customSpinnerAdapter = new CustomSpinnerAdapter(this,R.layout.spinner_item,CustomListViewValuesArr);
mSpinner.setAdapter(customSpinnerAdapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
itemSelect(pos);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
Auch dies der Spinner in der Layout
des Activity
ist:
<Spinner
android:id="@+id/spinner"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spinnerMode="dropdown"
android:background="@null"
android:padding="0dp"
android:layout_margin="15dp"
android:dropDownVerticalOffset="@dimen/vertical_offset"/>
ich meine eigene benutzerdefinierte verwenden Adapter
:
public class CustomSpinnerAdapter extends ArrayAdapter {
public ArrayList CustomListViewValuesArr;
LayoutInflater inflater;
Typeface myTypeFace;
SpinnerItem item = null;
public CustomSpinnerAdapter(Context context, int textViewResourceId, ArrayList CustomListViewValuesArr) {
super(context, textViewResourceId, CustomListViewValuesArr);
this.CustomListViewValuesArr = CustomListViewValuesArr;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.myTypeFace = Typeface.createFromAsset(context.getAssets(),"fonts/OpenSans-Regular.ttf");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomDropDownView(position, convertView, parent);
}
public View getCustomDropDownView(int position, View convertView, ViewGroup parent) {
Log.d("","CustomListViewValuesArr" + position);
/********** Inflate spinner_rows.xml file for each row (Defined below) ************/
View row = inflater.inflate(R.layout.simple_spinner_dropdown_item, parent, false);
item = (SpinnerItem) CustomListViewValuesArr.get(position);
/***** Get each Model object from Arraylist ********/
TextView label = (TextView)row.findViewById(R.id.spinner_drop_down);
// Default selected Spinner item
label.setText(item.getFilterName());
label.setTypeface(myTypeFace);
return row;
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
Log.d("","CustomListViewValuesArr" + position);
/********** Inflate spinner_rows.xml file for each row (Defined below) ************/
View row = inflater.inflate(R.layout.spinner_item, parent, false);
item = (SpinnerItem) CustomListViewValuesArr.get(position);
/***** Get each Model object from Arraylist ********/
TextView label = (TextView)row.findViewById(R.id.spinner_item);
TextView hint = (TextView)row.findViewById(R.id.spinner_hint);
hint.setTypeface(myTypeFace);
// Default selected Spinner item
label.setText(item.getFilterName());
label.setTypeface(myTypeFace);
return row;
}
}
Und schließlich verwende ich benutzerdefinierte Ansichten für das Dropdown
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:elevation="-6dp"
android:layout_height="35dp">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/spinnerDropDownItemStyle"
android:singleLine="true"
android:id="@+id/spinner_drop_down"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@color/spinner_font_color"
android:layout_marginLeft="20dp"
android:textSize="14sp"
android:layout_marginStart="20dp"
android:ellipsize="marquee">
</TextView >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_hint_change_pass"/>
und für die Spinner
Artikel
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:ellipsize="marquee"
android:background="@drawable/spinners_background"
style="@style/spinnerItemStyle"
android:layout_height="35dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/spinner_hint"
android:gravity="center"
android:textStyle="bold"
android:textColor="@color/spinner_font_color"
android:textSize="14sp"
android:id="@+id/spinner_hint"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_alignTop="@+id/spinner_item" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner_item"
android:textColor="@color/spinner_header_color"
android:gravity="center"
android:text="sss"
android:textSize="14sp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/spinner_hint"
android:layout_toEndOf="@+id/spinner_hint" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/down_arrow_spinner"
android:layout_marginRight="17dp"
android:layout_marginEnd="1dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/imageView2" />
Was ich versucht habe und nicht gearbeitet haben:
- hinzufügen Elevation
Vielen Dank im Voraus im Spinner
Widget