How can I add gradient effect to background color of TextView in a ListView?

前端 未结 3 2028
渐次进展
渐次进展 2020-12-24 01:54

In reference to these questions :

Adding gradient effect to TextView in a ListView generates NPE

and

How to change color and font on ListView

<
3条回答
  •  误落风尘
    2020-12-24 01:58

    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):

    android:background="@drawable/customshape"
    

提交回复
热议问题