java - 图像灰色直到点击 - 改变颜色并记住点击的图像
问题描述
当我的用户第一次登陆主要活动时,我希望图块(图像视图)变灰且不可点击。只有第一个图块应该是彩色的并且可以点击。在用户访问第一个图块并返回到主要活动后,下一个图块将变为彩色且可点击,依此类推。
这个想法是在第一次使用该应用程序时引导用户完成序列。我猜这些信息需要存储在共享首选项中,因为我只希望第一次发生这种情况。随后,所有瓷砖都应该是彩色的并且可以点击。
有人可以帮我实现这一目标吗?目前我有一个 switch 语句,一个布尔和彩色/灰色版本的图像块。
@Override
public void onClick(View v) {
SharedPreferences.Editor introEditor = introPref.edit();
switch (v.getId()) {
case R.id.cbt_button_grey:
Intent mainIntent = new Intent(getActivity(), IntroActivity2.class);
startActivity(mainIntent);
hasSelected = true;
introEditor.putBoolean("hasSelected", hasSelected);
introEditor.commit();
break;
case R.id.twisted_thinking_button_grey:
hasSelected = true;
Intent distortedIntent = new Intent(getActivity(), TwelveTypesDistortedThinkingSliderActivity.class);
startActivity(distortedIntent);
break;
case R.id.workout_button_grey:
hasSelected = true;
Fragment workoutFragment = new WorkoutFragment();
FragmentTransaction workoutTransaction = getActivity().getSupportFragmentManager().beginTransaction();
workoutTransaction.replace(R.id.fragment_container, workoutFragment);
workoutTransaction.commit();
break;
case R.id.workout_log_button_grey:
hasSelected = true;
Fragment workoutLogFragment = new WorkoutLogFragment();
FragmentTransaction workoutLogTransaction = getActivity().getSupportFragmentManager().beginTransaction();
workoutLogTransaction.replace(R.id.fragment_container, workoutLogFragment);
workoutLogTransaction.commit();
break;
case R.id.mood_log_button:
hasSelected = true;
Fragment moodLogFragment = new MoodLogFragment();
FragmentTransaction moodLogTransaction = getActivity().getSupportFragmentManager().beginTransaction();
moodLogTransaction.replace(R.id.fragment_container, moodLogFragment);
moodLogTransaction.commit();
break;
case R.id.activities_button_grey:
hasSelected = true;
Fragment activitiesFragment = new ActivitiesFragment();
FragmentTransaction activitiesTransaction = getActivity().getSupportFragmentManager().beginTransaction();
activitiesTransaction.replace(R.id.fragment_container, activitiesFragment);
activitiesTransaction.commit();
break;
}
}
解决方案
在 MainActivity 类中使用 startActivityForResult() 怎么样。您可以覆盖 onActivityResult() 以启用/禁用图像。这只是一个建议。
推荐阅读
- python - 我怎样才能给 UHD: USRP Source 一个命令来改变一些采样后的中心频率?
- python - 使用 Appium 和 Python for IOS 从另一个测试脚本自动调用另一个测试脚本
- mongodb - 在 aws ec2 中,mongodb 无法启动
- ios - UITableview 部分 - 如何正确重新计算高度?
- ios - 强制 WKWebView 显示桌面版本
- elixir - 有没有办法将一个模块的内容完全插入另一个模块?
- sql-server - SQL Server如何交换日期和月份
- skrill - Skrill:在 Skrill 中创建定期计费配置文件的正确方法是什么
- android - Firebase令牌ID在android中为空
- statistics - SPSS统计