Android view turn off implicit state retaining for some view

后端 未结 2 1853
生来不讨喜
生来不讨喜 2021-02-05 03:24

I have custom View which is dynamically added multiple times in same activity.

Each of custom view instance has beside other stuff a

2条回答
  •  日久生厌
    2021-02-05 03:45

    if you need apply setSaveEnabled for all hierarchy:

        public static void SaveEnableViewAndChildren(this View view, bool val)
        {
            if (view == null)
                return;
            view.SaveEnabled = val;
    
            var viewGroup = view as ViewGroup;
            if (viewGroup == null)
                return;
            for (int i = 0; i < viewGroup.ChildCount; i++)
                SaveEnableViewAndChildren(viewGroup.GetChildAt(i), val);
        }
    

提交回复
热议问题