Java Question Recreate view object in DesignerCreateView?

corwin42

Expert
Licensed User
Longtime User
Hello,

I am planning to add style support to all views in AppCompat library.

All the views are based on ViewWrapper. So currently the base object like AppCompatButton is created in innerInitialize method. This will remain in the future so that it is compatible to initializing the object manually with Button1.Initialize().
There will be a Initialize2(..., Style as String) method to initialize a View manually with a given style.

Additionally I want to add a style property to the designer. If it is set it is required that the base object is recreated in DesignerCreateView(). This is done in the following way:

B4X:
    public void DesignerCreateView(PanelWrapper base, LabelWrapper label, Map props) {
        android.view.ContextThemeWrapper wrapper;


        if (props.Get("Style") != null && !(props.Get("Style").toString().isEmpty())) {
            wrapper = new android.view.ContextThemeWrapper(super.ba.context, BA.applicationContext.getResources().getIdentifier((String) props.Get("Style"), "style", BA.packageName));
            this.setObject(new AppCompatButton(wrapper));
        }

[...]

        CustomViewWrapper.replaceBaseWithView2(base, getObject());
    }

Do you see any problems in doing this? Actually the Toolbar uses a similar method to set the theme (dark or light) and it seems to work reliably.
 
Top