How to customise the TextView inside a Spinner?

十年热恋 提交于 2019-12-03 07:47:28

Override the getView method of the Adapter to create a custom list view item.

View getView(int position, View  convertView, ViewGroup  parent) {
     TextView tv = null;
     if(covertView instanceof TextView) {
          tv = (TextView) convertView;
     } else {
          tv = new TextView(this);
          tv.setText("Awesome Text");
     }
     return tv;
}

Also when you create the adapter you can pass in a layout to use for the item, so in that case ConvertView would be a RelativeLayout or LinearLayout.

The answer was to remove the padding from the definition of the Spinner. Every time I set the padding of the Spinner the Text gets out of shape.

The spinner drawable is using the padding box from the nine patch to determine where to draw the the content. If I set a padding manually the definition of the padding from the padding box will be overridden.

If you want to set a padding in addition to a padding box you need to wrap everything inside that paddinbox into an additional Layout container.

use /home/user/android-sdk-linux/tools/./draw9patch (it's for linux), on Windows go to tools on android-sdk-windows directory and execute draw9patch.

and use so image, ex:

Attention for de black lines in image. (this black lines are generates by draw9patch)

Image results add on extension file 9, ex: img.9.png (IMG EXPANSIVE HORIZONTAL AND VERTICAL)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!