Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On GingerBread, ListView's background looks wried with material theme when one of its item is pressed. #17

Closed
fengdai opened this issue Nov 29, 2014 · 19 comments
Labels

Comments

@fengdai
Copy link
Owner

fengdai commented Nov 29, 2014

On GingerBread emulator. Choose Material theme(or Material light theme), and show "List Dialog"(or any other dialog contains ListView) . Then press an item and all the other items look like being pressed.

17

@fengdai fengdai added the bug label Nov 29, 2014
@fengdai fengdai changed the title On GingerBread, ListView's background looks wried with material theme. On GingerBread, ListView's background looks wried with material theme when on of its item is pressed. Nov 29, 2014
@fengdai fengdai changed the title On GingerBread, ListView's background looks wried with material theme when on of its item is pressed. On GingerBread, ListView's background looks wried with material theme when one of its item is pressed. Nov 29, 2014
@AndroidDeveloperLB
Copy link

ummm... I don't see this issue. Are you sure it's there?

@fengdai
Copy link
Owner Author

fengdai commented Nov 29, 2014

Yes, I'm sure. My emulator's Android version is 2.3.3.

@AndroidDeveloperLB
Copy link

But I can't reproduce it on the emulator. Odd.

@fengdai
Copy link
Owner Author

fengdai commented Nov 29, 2014

Press one item, and don't release your finger.

@AndroidDeveloperLB
Copy link

oops. I missed this part. How could it be?

@fengdai
Copy link
Owner Author

fengdai commented Nov 29, 2014

I also want to know…

@AndroidDeveloperLB
Copy link

Here's what I did in my app. It avoids this issue by having a simple ListView.
Maybe it could help.

Single selection:

final ArrayAdapter<String> adapter=new ArrayAdapter<String>(activity,//
    android.R.layout.simple_list_item_single_choice,itemsStrs);
final AlertDialogPro.Builder builder=new AlertDialogPro.Builder(dialogStyle);
builder.setTitle(...);
final ListView listView=new ListView(activity);
builder.setView(listView);
final AlertDialogPro dialog=builder.setCancelable(true).create();
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setAdapter(adapter);
listView.setItemChecked(selectedIndex,true);
listView.setOnItemClickListener(new OnItemClickListener()
  {
    @Override
    public void onItemClick(final AdapterView<?> parent,final View view,final int position,final long id)
      {
      ...
      }
  });
dialog.show();

Multi-selection:

final AlertDialogPro.Builder builder=new AlertDialogPro.Builder(activity,dialogStyle);
builder.setTitle(...);
builder.setNegativeButton(android.R.string.cancel,null);   
final ArrayAdapter<String> adapter=new ArrayAdapter<String>(activity,//
    android.R.layout.simple_list_item_multiple_choice,//
    itemsStr);
final ListView listView=new ListView(activity);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
builder.setPositiveButton(android.R.string.ok,new OnClickListener()
  {
    @Override
    public void onClick(final DialogInterface dialog,final int which)
      {
      final SparseBooleanArray checkedItemPositions=listView.getCheckedItemPositions();
      ...
      }
  });
builder.setView(listView);

@fengdai
Copy link
Owner Author

fengdai commented Nov 29, 2014

Thank you @AndroidDeveloperLB,What's the style xml of your ListView.

@AndroidDeveloperLB
Copy link

I didn't set a style for the listView.
Only the style of the dialog is written, and that's just those that you use in your library.
Do you think that the "adapter" variable uses the theme of the activity ?

@fengdai
Copy link
Owner Author

fengdai commented Nov 30, 2014

Your ListView use the activity's theme:

final ListView listView=new ListView(activity);

So what's your activity's theme?

I created a dialog as your way. It looked like this("Male" item is pressing):
17_

It doesn't has this issue, because the list selector is a drawable with "Holo" color. And this is its xml file:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_window_focused="false" android:drawable="@android:color/transparent" />

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
<item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
<item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
<item android:state_focused="true"                                                             android:drawable="@drawable/abc_list_focused_holo" />

This is my material item background:

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/adp_mtrl_ripple_light" android:state_pressed="true" />
    <item android:drawable="@android:color/transparent" />
</selector>

I think the difference is that the above uses image resource as its drawable:

<item android:state_focused="false"  android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />

And mine, use color:

<item android:drawable="@color/adp_mtrl_ripple_light" android:state_pressed="true" />

When I replaced "@color/adp_mtrl_ripple_light" with a "Shape" drawable, the issue gone:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <solid android:color="@color/adp_mtrl_ripple_light" />
</shape> 

So I think this would be the point. But I still don't know the actual reason...

@AndroidDeveloperLB
Copy link

Well the activity has the theme of the library, with just a few adjustments for other stuff, but as I remember they shouldn't affect ListViews in general...
Here are some parts of it, that use the native attributes:

    <item name="colorPrimary">@color/normal_window_background__light</item>
    <item name="android:textColorPrimary">@android:color/black</item>
    <item name="android:textColorSecondary">@android:color/black</item>
    <item name="android:textColorTertiary">@android:color/black</item>
    <item name="android:windowBackground">@color/normal_window_background__light</item>

The rest is just customized attributes that I've created for very specific usages (because my app has multiple themes the user can choose from).

@MoonlightMultimedia
Copy link

Same issue here.

fengdai added a commit that referenced this issue Jan 10, 2015
@fengdai
Copy link
Owner Author

fengdai commented Jan 10, 2015

@RaymondBakkerMoonlightMultimedia I think this is caused by an issue of old platform's ListView(Not very sure). Here is a workaround: 3ab68ad

@AndroidDeveloperLB
Copy link

what exactly have you changed?

@MoonlightMultimedia
Copy link

@AndroidDeveloperLB Seems old Android verions behave differently when using @color or @drawable resources. I have yet to test to verify that it has been fixed.

@AndroidDeveloperLB
Copy link

Ohhh... I remember I read about it somewhere. in order to use a color, you have to use a drawable that has it inside a "shape" xml tag.

@MoonlightMultimedia
Copy link

Just tested it, can confirm that it has been fixed!

@marbat87
Copy link

Could you please publish the new version on Maven? Thanks in advance

@fengdai
Copy link
Owner Author

fengdai commented Jan 15, 2015

@marbat87 0.2.1 is available now.

@fengdai fengdai closed this as completed Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants