我是android的新手,我用图像显示recyclerview,所有图片保存在drawable文件夹中,它的工作正常,但我需要调色板颜色到我的textview,我不知道如何实现这个任何一个请帮我怎么样得到这个,来自本地的所有图像
这是我的班级
PrimaryFrragment.Class
public class PrimaryFragment extends Fragment {
private SimpleCardViewAdapter mAdapter;
private RecyclerView mRecyclerView;
public PrimaryFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootview= inflater.inflate(R.layout.fragment_primary, container, false);
mRecyclerView = (RecyclerView)rootview. findViewById(R.id.list);
mRecyclerView.setItemAnimator(new BaseItemAnimator() {
@Override
protected void animateRemoveImpl(RecyclerView.ViewHolder holder) {
}
@Override
protected void animateAddImpl(RecyclerView.ViewHolder holder) {
}
});
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mAdapter = new SimpleCardViewAdapter(getActivity(),Arrays.asList(
new CardViewData("BUNNY", "Description of Item 0", R.drawable.bunny),
new CardViewData("Sample Title Item 1", "Description of Item 1", R.drawable.bunny_four),
new CardViewData("Sample Title Item 2", "Description of Item 2", R.drawable.bunny_one),
new CardViewData("Sample Title Item 3", "Description of Item 3", R.drawable.bunny_four),
new CardViewData("Sample Title Item 4", "Description of Item 4", R.drawable.bunny_one)));
mRecyclerView.setAdapter(mAdapter);
return rootview;
}
}
SampleAdapter.class
public class SimpleCardViewAdapter extends RecyclerView.Adapter<SimpleCardViewAdapter.ViewHolder> {
private int lastPosition = -1;
private Context context;
private List<CardViewData> mDataset;
public SimpleCardViewAdapter(Context context,List<CardViewData> dataset) {
mDataset = dataset;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.primary_layout, viewGroup, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final ViewHolder viewHolder, int i) {
final CardViewData cardViewData = mDataset.get(i);
viewHolder.mTitle.setText(cardViewData.getTitle());
viewHolder.mDescription.setText(cardViewData.getDescription());
viewHolder.mImage.setImageResource(cardViewData.getImage());
Animation animation = AnimationUtils.loadAnimation(context,
(i > lastPosition) ? R.anim.up_from_bottom
: R.anim.down_from_top);
viewHolder.itemView.startAnimation(animation);
lastPosition = i;
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "Title: " + cardViewData.getTitle(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return mDataset == null ? 0 : mDataset.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTitle;
public TextView mDescription;
public ImageView mImage;
public ViewHolder(View itemView) {
super(itemView);
mTitle = (TextView) itemView.findViewById(R.id.row_title);
mDescription = (TextView) itemView.findViewById(R.id.row_description);
mImage = (ImageView) itemView.findViewById(R.id.row_image);
}
}
}