首页 > recyclerView 长按处于激活状态,背景色设置失败。

recyclerView 长按处于激活状态,背景色设置失败。

item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background_active"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/content_editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"/>
    </android.support.v7.widget.CardView>
</RelativeLayout>

Main.xml

        .....
        <android.support.v7.widget.RecyclerView
            android:id="@+id/TODO_recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        .....

adapter

public class TODOListAdapter extends RecyclerView.Adapter<TODOListAdapter.TODOHolder> {
    public class TODOHolder extends RecyclerView.ViewHolder{
        public TODOHolder(final View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
                        itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onLongClickViewHolderListener.onLongClick();
                    itemview.setActived(true);
                }
            });
          }

MainActvity实现方法

@Override
    public void onLongClick(View v) {
        startActionMode(new LongOnClickCallBack());
    }

drawable/xml

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

itemview.setActived(true)只有边缘可以显示,请问我哪里做错了吗?应该如何设置使得全部处于激活状态.


是我对background 这个属性理解错了,覆盖在上面的cardview是无法被覆盖的,改成类似于LinearLayout之类的容器可以解决.

【热门文章】
【热门文章】