In reference to these questions :
Adding gradient effect to TextView in a ListView generates NPE
and
How to change color and font on ListView
I would like to know how to go about setting the background of a TextView
in a ListView
with gradient effect?
In one of the questions above, I ended up having the gradient effect added to the text in the TextView
. And after skimming through the second question, it seems I can add only fixed background colors.
How do I go about adding gradient to background? Should I make a CustomListAdapter
?
Once you create a gradient you can apply it to pretty much anything let it be textView, layout or button.
To understand how to create and use a gradient refer this link.
To create a gradient you need to add it to the below directory
Code for gradient would be something like this -
You just need to create a drawable resource (see an example below), and add it to the layout you created for your ListItem.
The drawable (in your res\drawable folder - name it whatever - listgrad.xml for ex) could look like:
The you would add it to the layout for your list item (the layout.xml file you define for this) like this code snippet:
Referred from here : How do I create a ListView with rounded corners in Android? (I have found it very useful.)
Add the following into a file (say gradient.xml) and then place it in (res/drawable/gradient.xml) directory.
Once you are done with creating this file,just set the background in one of the following ways:
Through Code:
listView.setBackgroundResource(R.drawable.customshape);
Through XML,just add the following attribute to the container (ex: LinearLayout or to any fields):