更改android中的微调按钮样式

时间:2011-03-21 19:25:37

标签: android coding-style spinner

如何更改微调器按钮的外观?现在,我只需要减小字体大小。只需按钮,列表就可以了。感谢

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

为此,您需要创建一个新的布局,用于定义微调器的外观。 spinner_item。您可以按如下方式使用它。因此,可以更改微调器中的背景,视图等属性。

 ImageSpinnerAdapter adapterForImageSpinner = new ImageSpinnerAdapter(this, true,
            spinnerData, R.layout.spinner_view, new String[] { "Name",
                    "Icon" }, new int[] {R.id.imageNameSpinner,
                    R.id.imageIconSpinner }, spinnerImages);

这将在适配器中使用,如下所示:

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;
}

}

答案 2 :(得分:0)

如果您想要做的是更改实际的微调器大小,请将其设置得更低,只需在xml上使用layout_height:

机器人:layout_height = “40dip”

少于此,带箭头的按钮看起来不太好。