Android view turn off implicit state retaining for some view

后端 未结 2 1852
生来不讨喜
生来不讨喜 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);
        }
    
    0 讨论(0)
  • 2021-02-05 04:02

    You can use View.setSaveEnabled (boolean enabled) method.

    It's also possible to disable automatic state saving via xml using saveEnabled attribute android:saveEnabled="false"

    0 讨论(0)
提交回复
热议问题