Reputation: 775
I have write this code for dropdown in android xml
<Spinner
android:id="@+id/gender"
android:layout_height="31dp"
android:layout_width="150dp"
android:entries="@array/gender"
android:prompt="@string/gender_select"
android:background="@drawable/textbox_bg_image">
</Spinner>
Screen is looks like this type
it's dropdown height or width i can define but i click on it a list come out for options 'male' and 'female' ..
i can't cantrol this selection option list.. can we control drop down background or height and width....
Upvotes: 0
Views: 1567
Reputation: 4382
//it will help you to achieve this
genderAdapter = new ArrayAdapter<String>(context,
R.layout.my_spinner_style, subjectList) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
Typeface externalFont = Typeface.createFromAsset(getAssets(),
"ArchitectsDaughter.ttf");
((TextView) v).setTypeface(externalFont);
return v;
}
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
View v = super.getDropDownView(position, convertView, parent);
Typeface externalFont = Typeface.createFromAsset(getAssets(),
"ArchitectsDaughter.ttf");
((TextView) v).setTypeface(externalFont);
v.setBackgroundColor(Color.GRAY);
((TextView) v).setTextColor(Color.parseColor("#FFFFFF"));
return v;
}
//above code will help to give background color for dropdown spinner and to customize the font . width of drop down depends on width of spinner.Below is the my_spinner_style.xml for customizing text
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="#ffffff" />
Upvotes: 1
Reputation: 1710
Create a custom spinner Adapter and then use the getDropDownView() method.
eg:
adapter = new ArrayAdapter<String>(ActivityName.this,
R.layout.custom_spinner, gender_arraylist) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
return v;
}
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
View v = super.getDropDownView(position, convertView, parent);
//change height and width or text size and colour here
return v;
}
};
Upvotes: 1