code: @Nullable
      public static String setVariantForView(@NonNull View view, @NonNull AttributeSet attrs) {
          String previousVariant;
          final TypedArray styledAttributes = view.getContext().getTheme()
                  .obtainStyledAttributes(attrs, R.styleable.View, 0, 0);
          try {
              previousVariant = setVariantForView(view, styledAttributes
                      .getString(R.styleable.View_variant));
          } finally {
              styledAttributes.recycle();
          }
  
          return previousVariant;
      }
docs: Associates programmatically a view with its variant, taking it from its `variant` layout attribute.
  
  @param view  any existing view.
  @param attrs the view's AttributeSet.
  @return the previous variant for this view, if any.