,
<Spinner
android:id="@+id/spinner1"
style="?android:attr/spinnerStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/dropdown"
android:dropDownVerticalOffset="1dp"
android:focusable="false"
android:spinnerMode="dropdown" />
,
spinner_text_layout.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_for_spinner"
style="?android:attr/spinnerItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="10dp"
android:drawableRight="@drawable/arrow"
android:gravity="center"
android:textColor="@android:color/white" >
</TextView>
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.spinner_text_layout, null);
}
TextView textView = (TextView) convertView
.findViewById(R.id.text_for_spinner);
textView.setText((String) getItem(position));
notifyDataSetChanged();
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.spinner_text_layout, null);
}
TextView textView = (TextView) convertView
.findViewById(R.id.text_for_spinner);
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
textView.setText((String) getItem(position));
textView.setTextColor(Color.BLACK);
textView.setBackgroundResource(R.drawable.drop_down_selector);
return convertView;
}
source
share