how to set text colour for entries in listview in andrid

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to set text colour for entries in listview in andrid

Postby poch » Wed Dec 02, 2009 1:52 pm

Here is my problem:

I want to set text colour for entries in listview .And i want to edit the size of that background shell of each elment in listview.Could you please provide me some example xml file with proper attributes.
poch
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Nov 29, 2009 5:55 pm
Location: INDIA

Top

Postby achie1266 » Wed Dec 02, 2009 5:13 pm

One method is to set it in the textview of each list item. Use android:textColor

ex:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3.  
  4. <LinearLayout
  5.  
  6.         xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="wrap_content"
  11.  
  12.         android:padding="1sp">
  13.  
  14.        
  15.  
  16.         <TextView
  17.  
  18.                 android:id="@+id/name"
  19.  
  20.                 android:layout_width="fill_parent"
  21.  
  22.                 android:layout_height="wrap_content"
  23.  
  24.                 android:textColor="@color/simpleBlueText" />
  25.  
  26.  
  27.  
  28. </LinearLayout>
  29.  
  30.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Or you may set the textcolor of the entire app in the theme also but it may be involve a lot more work than this.
I am guessing that the first option will do what you needed.

There is also another element textSize to set the size of the text fields.
Hope this helps you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

how to set text colour for entries in listview in andrid

Postby poch » Thu Dec 03, 2009 4:40 am

Thank you.

I need to pass sring array through listview and display that array elements on screen.Here the default text color of string elements is white . I just change the background color of the listview to black then evrything is fine.

But my requirement is display the string elements in white background with black text color. And reduce the display space between each String array element.

I hope you give me the solution with an example code.
poch
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Nov 29, 2009 5:55 pm
Location: INDIA

Re: how to set text colour for entries in listview in andrid

Postby achie1266 » Thu Dec 03, 2009 6:12 pm

poch wrote:Thank you.

I need to pass sring array through listview and display that array elements on screen.Here the default text color of string elements is white . I just change the background color of the listview to black then evrything is fine.

But my requirement is display the string elements in white background with black text color. And reduce the display space between each String array element.

I hope you give me the solution with an example code.


Did you try the padding which i showed you in the example that i gave above to reduce the spacing between elements?
To change the background you need to set the background in the same linearlayout or whatever you are using.
I did not get why the text color did not work for you.

Can you post that code of the layout file so that I may be able to understand it and help you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby qlimax » Thu Dec 03, 2009 7:45 pm

poch, you need to build your custom listview-> with your custom arrayadapter. in this way, you can define the layout used for each item of your listview, like achie1266 says:

achie1266 wrote:One method is to set it in the textview of each list item. Use android:textColor

ex:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout
  3.         xmlns:android="http://schemas.android.com/apk/res/android"
  4.         android:layout_width="fill_parent"
  5.         android:layout_height="wrap_content"
  6.         android:padding="1sp">
  7.        
  8.         <TextView
  9.                 android:id="@+id/name"
  10.                 android:layout_width="fill_parent"
  11.                 android:layout_height="wrap_content"
  12.                 android:textColor="@color/simpleBlueText" />
  13.  
  14. </LinearLayout>
  15.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Or you may set the textcolor of the entire app in the theme also but it may be involve a lot more work than this.
I am guessing that the first option will do what you needed.

There is also another element textSize to set the size of the text fields.
Hope this helps you.


you can set the background of the layout to white, and the textcolor of the textview to black, and many other properties you want


bye ;)
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby tbennett » Fri Dec 04, 2009 1:33 am

put this in a file in your res/layout directory named simple_list_item_inverse.xml:


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4.  android:id="@android:id/text1"
  5.  
  6.  android:layout_width="fill_parent"
  7.  
  8.  android:layout_height="wrap_content"
  9.  
  10.  android:textAppearance="?android:attr/textAppearanceLargeInverse"
  11.  
  12.  android:gravity="center_vertical"
  13.  
  14.  android:paddingLeft="6dip"
  15.  
  16.  />
  17.  
  18.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


you can also use

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.   android:textAppearance="?android:attr/textAppearanceMediumInverse"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


... or

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.   android:textAppearance="?android:attr/textAppearanceSmallInverse"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


... and if none of those fit your sizing requirements you need to set the text size, color, padding yourself:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.   android:textSize="12dp"
  4.  
  5.   android:textColor="@android:color/black"
  6.  
  7.   android:paddingTop="4dp"
  8.  
  9.   android:paddingBottom="4dp"
  10.  
  11.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


In your layout XML where you define your ListView (or if you do it in code), set the background and cacheColorHint to white:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <ListView
  3.  
  4.  android:id="@+id/list"
  5.  
  6.  android:background="@android:color/white"
  7.  
  8.  android:cacheColorHint="@android:color/white"
  9.  
  10.  android:layout_width="fill_parent"
  11.  
  12.  android:layout_height="fill_parent"
  13.  
  14.  />
  15.  
  16.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


... then in your code create an ArrayAdapter and use the simple_list_item_inverse.xml that you just defined:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. final ArrayAdapter<String> adapter =
  3.  
  4.   new ArrayAdapter<String>(
  5.  
  6.     YourActivity.this,
  7.  
  8.     R.layout.simple_list_item_inverse,
  9.  
  10.     new String[] {"This","That","Other"}
  11.  
  12.   );
  13.  
  14.  
  15.  
  16. final ListView list = (ListView)findViewById(R.id.list);
  17.  
  18. list.setAdapter(adapter);
  19.  
  20.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
tbennett
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Dec 07, 2008 7:58 am

Top

Postby poch » Wed Dec 09, 2009 9:31 am

Thank you very much guys.I have made use of this thing in my project module its working fine.
poch
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Nov 29, 2009 5:55 pm
Location: INDIA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests