Skip to content

Commit

Permalink
add ability to set and change text color in a RecyclerView
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Zhang authored and Eric Zhang committed Mar 3, 2016
1 parent 5ffd573 commit 2efb472
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/com/mingle/myapplication/MainActivity.java
Expand Up @@ -63,13 +63,15 @@ public void onClick(View v) {

private void setupRecyclerView() {

ArrayList<MenuEntity> list = new ArrayList<>();
final ArrayList<MenuEntity> list = new ArrayList<>();
//添加假数据
MenuEntity menuEntity1 = new MenuEntity();
menuEntity1.iconId = R.drawable.ic_account_child;
menuEntity1.titleColor = 0xff000000;
menuEntity1.title = "code";
MenuEntity menuEntity = new MenuEntity();
menuEntity.iconId = R.drawable.ic_account_child;
menuEntity.titleColor = 0xffb3b3b3;
menuEntity.title = "QQ";
list.add(menuEntity1);
list.add(menuEntity);
Expand Down Expand Up @@ -97,10 +99,13 @@ private void setupRecyclerView() {
mSweetSheet.setOnMenuItemClickListener(new SweetSheet.OnMenuItemClickListener() {
@Override
public boolean onItemClick(int position, MenuEntity menuEntity1) {
//即时改变当前项的颜色
list.get(position).titleColor = 0xff5823ff;
((RecyclerViewDelegate) mSweetSheet.getDelegate()).notifyDataSetChanged();

//根据返回值, true 会关闭 SweetSheet ,false 则不会.
Toast.makeText(MainActivity.this, menuEntity1.title + " " + position, Toast.LENGTH_SHORT).show();
return true;
return false;
}
});

Expand Down
Expand Up @@ -70,6 +70,7 @@ public void onBindViewHolder(MenuVH menuVH, int i) {
menuVH.iv.setVisibility(View.GONE);
}
menuVH.nameTV.setText(menuEntity.title);
menuVH.nameTV.setTextColor(menuEntity.titleColor);
if (mIsAnimation) {
animation(menuVH);
}
Expand Down
2 changes: 2 additions & 0 deletions sweetsheet/src/main/java/com/mingle/entity/MenuEntity.java
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.annotation.ColorInt;


/**
Expand All @@ -15,6 +16,7 @@
public class MenuEntity {

public @DrawableRes int iconId;
public @ColorInt int titleColor;
public CharSequence title;
public Drawable icon;

Expand Down
Expand Up @@ -120,6 +120,10 @@ public void onAnimationRepeat(Animation animation) {

}

public void notifyDataSetChanged() {
mMenuRVAdapter.notifyDataSetChanged();
}

protected void show() {
super.show();
ViewGroup.LayoutParams lp =
Expand Down
4 changes: 4 additions & 0 deletions sweetsheet/src/main/java/com/mingle/sweetpick/SweetSheet.java
Expand Up @@ -66,6 +66,10 @@ public void setDelegate(Delegate delegate){

}

public Delegate getDelegate() {
return mDelegate;
}


private void setup() {

Expand Down

0 comments on commit 2efb472

Please sign in to comment.