Android Question ListView renders incorrectly for API Level 24

Sandman

Expert
Licensed User
Longtime User
Summary:
ListView in API Level 24 is not rendered correctly

Listview as seen in Level 23 (correctly):
Screenshot_20170515-165357.png


ListView as seen in Level 24 (not readable):
Screenshot_20170515-165318.png


Reproduction Steps:
1. Add a listview to a layout
2. Add a line to the listview
3. Set manifest to use targetSdkVersion=24

Actual Behavior:
The added line is not visible. (I'm guessing it's the same color as the background.)

Expected Behavior:
The line is visible.

Notes (optional):
I'm not entirely sure this is a bug, but I can't imagine what I'm doing wrong otherwise.

Additional information (optional):
Project attached. You need to manually edit the manifest between 23 and 24 for targetSdkVersion to see the issue.
 

Attachments

  • listview_bug.zip
    8.5 KB · Views: 218

ronell

Well-Known Member
Licensed User
Longtime User
you can try

B4X:
if p.sdkversion <= 23 then
'do nothing
else
'do the code here to make the background color black
end if
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
It is better to explicitly decide whether you want a light or dark theme (code to set light theme is available here: https://www.b4x.com/android/forum/threads/b4a-v5-80-beta-is-released.63300/#content).

Yes, I understand that I can change the colors in all kinds of ways, which is a very nice feature to have.

But why does the Default text color for CheckBox (and the other reference views) change correctly and not the Default for ListView? Is it not an identical situation? (This is why I posted this as a possible bug.)


you can try... (code removed)

Yes, I understand that I can do that. And, to take that reasoning to an extreme: I could make all my views from scratch by drawing on a canvas. But that's not what I tried to do. I just tried to slap a ListView on a Layout and let the OS render it using its defaults. It's a slippery path to go down if I code like you suggested. "If X then render like this, unless it's like that, in that case render like this" - it easily turns into am awful decision tree where I need to take a lot of responsibility when all I wanted was for the OS to just give me the vanilla, default version.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Are you setting the colour of any of the items in the ListView?

What is your target sdk, in your manifest? You mention changing this, but you don't really need to...

Have you targeted a theme?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
In most cases the default color will indeed change based on the current theme. However this is not the case with ListView items. You can use CustomListView instead. The only reason to use ListView is if you want to show many (at least 1000) items.

Ah, I see, thank you. When I researched listviews last week I did indeed find CustomListView, and I did see you mentioning the size of the lists. But the ListView is built-in, and had this AddTwoLines method which was absolutely perfect for me. In the end I assumed this ListView was the most native of the two. (Especially since the other one was named "Custom".)

Now I understand the situation and I know several workarounds, which is good. Can I still request an update in a future version of B4A that the ListView uses the OS default color? (Or should I post it as a formal Wish?)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can I still request an update in a future version of B4A that the ListView uses the OS default color?
The default behavior cannot be changed as it will break the looks of existing applications. A possible solution is to allow setting the color to Transparent which will then be treated as the theme default color. I will check it.

CustomListView is based on ScrollView.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
The default behavior cannot be changed as it will break the looks of existing applications.

I'm not going to argue with you. I'll simply note that changing behavior would (as far as I can tell) only affect these users:
  1. They target 24 or 25, and
  2. They expect the listview text to be unreadable
...which seems like an exceptionally small group. :)
 
Upvote 0
Top