Change spinner button style in android
how can I change the look of a spinner's button ? For now, I just need to decrease the font si开发者_Go百科ze. Just the button, the list is ok. Thanks
How to change font style for spinner item
For this you need to create a new layout which defines the look of your spinner viz. spinner_item. You can use it as follows. Thus the properties like background, views include in the spinner can be changed.
ImageSpinnerAdapter adapterForImageSpinner = new ImageSpinnerAdapter(this, true,
spinnerData, R.layout.spinner_view, new String[] { "Name",
"Icon" }, new int[] {R.id.imageNameSpinner,
R.id.imageIconSpinner }, spinnerImages);
This will be used in the adapter as follows:
public class ImageSpinnerAdapter extends SimpleAdapter {
LayoutInflater mInflater;
private List<? extends Map<String, ?>> dataRecieved;
private int[] spinnerImagesReceived;
@SuppressWarnings("unused")
private HashMap<String, Object> data;
private boolean displayItems;
private int imageId;
private String imageText;
public ImageSpinnerAdapter(Context context, boolean displayItems,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to, int[] spinnerImages) {
super(context, data, resource, from, to);
this.displayItems = displayItems;
dataRecieved = data;
mInflater = LayoutInflater.from(context);
spinnerImagesReceived = spinnerImages;
}
@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.spinner_view, null);
}
data = (HashMap<String, Object>) getItem(position);
if (displayItems) {
setImageId(spinnerImagesReceived[position]);
setImageText((String) dataRecieved.get(position).get("Name"));
} else {
setImageText("");
setImageId(R.drawable.invalid);
}
((ImageView) convertView.findViewById(R.id.imageIconSpinner))
.setBackgroundResource(getImageId());
((TextView) convertView.findViewById(R.id.imageNameSpinner))
.setText(getImageText());
return convertView;
}
}
If what you wanna do is change the actual spinner size, make it less tall, just use the layout_height on your xml:
android:layout_height="40dip"
Less than that, the button with the arrow won't look good.
精彩评论