我有RecyclerView + cards。在卡片中,我在类视图中设置了随机颜色 -
` int[] androidColors = view.getResources().getIntArray(R.array.androidColors);
int randomAndroidColor = androidColors[new Random().nextInt(androidColors.length)];
if (frameLayout != null) {
frameLayout.setBackgroundColor(randomAndroidColor);
}`
通过单击卡片,打开活动。她的工具栏的颜色应该像卡片的颜色。
意图放额外我不能在这里使用,因为在意图中,我已经传递了标签。
public ViewHolder(View itemView) {
....
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
long poemId = (Long) v.getTag();
onPoemClickListener.onPoemClick(poemId);
}
});
}
}
public interface OnPoemClickListener {
void onPoemClick(long poemId);
}
回收器所在的片段类
private final PoemsAdapter.OnPoemClickListener onPoemClickListener = new PoemsAdapter.OnPoemClickListener() {
@Override
public void onPoemClick(long poemId) {
Intent intent = new Intent(getActivity(), ReadActivity.class);
intent.putExtra(ReadActivity.EXTRA_POEM_ID, poemId);
startActivity(intent);
}
};
如何获取我在活动中的适配器中生成的随机颜色?谢谢!
您可以根据需要放置任意数量的附加内容:
Intent intent = new Intent(getActivity(), ReadActivity.class);
intent.putExtra(ReadActivity.EXTRA_POEM_ID, poemId);
intent.putExtra("mycolor", color);
startActivity(intent);
然后在打开的活动中获取它,就像您获得任何其他额外值一样,