Modify Android ListView font size and color

Source: Internet
Author: User

The default font of the ListView in Android can sometimes not meet the needs of the design, need to design their own style,

The general online introduction is to create a new one of their own ListView adapter Myadapter, there is another way to avoid the trouble of new Myadapter.

1, the new Array_adapter.xml under the res/layout/:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <TextViewxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:id= "@+id/textview"4 Android:layout_width= "Wrap_content"5 Android:layout_height= "Wrap_content"6 android:textsize= "24SP"7 android:padding= "10DP" 8 Android:textcolor= "#ff000000"   9 ANDROID:SHADOWDX= "4"Ten Android:shadowdy= "4" One Android:shadowradius= "2" A  />

"Android:textsize" and "Android:textcolor" can specify the font size and color, of course, you can also make other settings such as adding a Shadow "Android:shadowcolor".

2. Create the adapter in Mainactivity and associate the Array_adapter.xml with the adapter:

1 PrivateListView m_loglist=NULL;2 PrivateArrayadapter adapter =NULL;3 PrivateArraylist<string>m_logtexts;4 5  Public voidonCreate (Bundle savedinstancestate) {6     Super. OnCreate (savedinstancestate);7     // .. .. ..8 9M_loglist = (ListView) This. Findviewbyid (r.id.listview1);Tenm_logtexts=NewArraylist<string>(); OneM_logtexts.add ("Hello World.")); AM_logtexts.add ("11 22 33"); -  -     //create the adapter and give the data to the adapter theadapter =NewArrayadapter ( This, r.layout.array_adapter,m_logtexts);  -     //add an adapter to the ListView - M_loglist.setadapter (adapter); -      + } -  +  Public voidOnLog (String str) { A  at      while(M_logtexts.size () >15) -     { -M_logtexts.remove (0); -     } - M_logtexts.add (str); -  in         //Notification Display - adapter.notifydatasetchanged (); to}


Effect

Modify Android ListView font size and color

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.