保留 TextView 颜色的状态

Retain State of TextView Color

我正在 LinearLayout 上渲染一些 TextViews。这些 TextView 保存用户可以 select 的时间。如果用户 select 使用它,TextView 的 颜色将设置为绿色。如果用户 select再次使用 TextView(时间),它会恢复为灰色。

所以行为应该是:如果 TextView unselected,保持灰色。如果TextView selected,变成绿色。这些 TextView 应该只在用户按下时改变颜色。

每当我在 LinerLayout 上滚动时,我都设法保留了 TextView 的 颜色的状态。但是,如果我按回键并保留 activity,TextViews 将全部重置为灰色。

是否可以保存 LinearLayout 的实例以及它的元素与 Firestore?如果您有任何建议,请告诉我。

Is it possible to save the instance of the LinearLayout and its elements with Firestore?

不,这是不可能的。 LinearLayout 不是使用 EventListener 的 supported data-type. What can you do instead, is to store the state of your button in Firestore and keep it always in sync with the server。因此,每次 select TextView 时,都会更新服务器上的状态。如果您离开 activity 并再次打开它,请从服务器读取上次更新的值。