Android 5.0+ 不会更改复选框图像

Android 5.0+ doesn't change checkbox image

我正在尝试制作一个自定义的多图像精选画廊。当我点击 CheckBox 日志时,一切正常:OnCheckedChangedOnClick 回调被触发,但没有动画,甚至没有简单的更改图片,我尝试手动调用view.invalidate() 但它也不起作用。我认为这是一种 AppCompat 库错误?我发现,在 5.0 之前一切正常。

这是 build.gradle 文件的一部分:

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

这里是 layout.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <include layout="@layout/recycler_view_item_picture"/>

  <CheckBox
      android:id="@+id/checked"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="end|top"/>

</FrameLayout>

这里是styles.xml:

 <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  </style>

  <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>

持有人代码如下:

public class PictureChooserItem extends RecyclerView.ViewHolder {

  @Bind(R.id.checked) CheckBox mChecked;
  @Bind(R.id.image) ImageView mImage;    

  public PictureChooserItem(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
  }

  @OnClick(R.id.image) public void onClick(View v) {
    Timber.d("OnClick!");
  }

  @OnCheckedChanged(R.id.checked) public void onCheckedChange(CompoundButton v, boolean flag) {
    Timber.d("OnChecked!");
  }

  public void bindFromCursor(Context ctx, Cursor cursor) {

    final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

    final GalleryUtils.GalleryImage item =
        new GalleryUtils.GalleryImage(cursor.getString(dataColumnIndex));
    Glide.with(ctx).load(item.path).asBitmap().placeholder(R.mipmap.ic_launcher).into(mImage);
  }
}

这是适配器代码(我使用 this 的子类):

@Override public void onBindViewHolder(PictureItem viewHolder, Cursor cursor) {
  viewHolder.bindFromCursor(mContext, cursor);
}

这里是截图

终于,我们找到了答案。

从支持片段迁移到 4.0+ 片段完成了工作。

关于支持片段管理器的问题。呼叫:

getSupportFragmentManager().executePendingTransactions();

也有帮助。