when I show my custom listviewitem to the user, all the items and objects contained in each item have the color that I want,
but when scrooling and selecting ( with onListItemClick ), the items don't change the background color for the desired color
Sounds like you need to set the cache color hint. This blog post -- http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html -- goes in to how to do that, and why you need to do it.
Try to add this to the onCreate method of your activity.
your_list_view.setCacheColorHint(0);
I had the same issue few days ago and it solved my problem. If you feel it is not what you need to do, then please post some code to have more details.
You will need to use selector for that. Check this http://android-codes-examples.blogspot.com/2011/03/customized-listview-items-selection.html
Read this note about CacheColorHints in the android reference guide:
http://developer.android.com/resources/articles/listview-backgrounds.html
it explains the concept behind it and why you need to set it to "#00000000" in your XML or 0 in your code.
Turns out, my view has a custom android:list<view>, and on my custom listview definition, i was using the android:background definition for each textview.
With this, I was not using the transparent or system defined color for background items on the listview. I removed this definition from my custom listview items definition, and the problem was solved.
Related
I am using the MaterialAutoCompleteTextView component. I would like if possible to set a different background color for selected item.
This is the current UI:
I would like to achieve this:
Any idea how to solve it?
I asked in the github and the solution is update the material library and use the property MaterialAutoCompleteTextView.setSimpleItemSelectedColor() to achieve that.
(only available since 1.7.0-alpha02.)
https://github.com/material-components/material-components-android/issues/2754
Can anyone give me some idea or code if possible regarding how to change the Theme of Listview ( like the back ground color, text color, icons etc) by clicking a button for example at runtime?
I saw an example here android dynamically change style at runtime.
I want to know if something similar is possible for List Views?
Thank You.
For changing the Bg color, you can set it dynamically.
mListView.setBackgroundColor(mColor); //doc
For changing the design in your listView, you have to set some variables, then use them in your custom adapter. When you click, you change these variables and call the notifyDataSetChanged() method.
Hope this will help you.
If I understand your question correctly, you want to customize the look and feel of the rows (individually or all) dynamically. If so, using a custom adapter and overriding the getView(...) function will probably work for you.
A quick explanation is available at http://www.mkyong.com/android/android-listview-example/
Hope this helps.
How to customize android spinner like this, and also the item of spinner also will look like this width. Is it possible to do this? If yes means tell the way. Otherwise what will do?
You have to create 2 or 3 state 9 patch image for the selected, pressed and default state of the Spinner and then use them as background of the Spinner.
Have a look at this post which beautifully explain all the process.
Hai!
In my application i want to change the listView text color in android.
How can i achieve this.
any solution will be appreciated...
ListView uses some optimizations when displaying itself, so you have to take some care when changing colors: http://developer.android.com/resources/articles/listview-backgrounds.html
You'll need to use a custom Adapter to do this. This tutorial looks pretty good: custom list view
The default color of the text is white. Let's say if i want to change the color, then how can i do it? Any clue?
in the getView method, find your TextView and set the color via setTextColor().
If you want your color changed for you based on the state of the item ( selected/focused etc) create new color in my_color.xml and define your states - examples of stateful colors are in SDK in res folders.
I highly recommened writing your own theme for the list view and then setting it in the layouts xml file, this means that you can use the same style throughout your app
This is a good tutorial to start with
http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/
One thing you could do is use your own layout for the list items. This way you could set whatever color or any other layout in the items.
You couldn't use setTextColor(); in your ListAdapter ? I think you could