无法在不适用于局部变量 butterknife 的局部变量“@BindViews”中使用

Unable to use in local variable '@BindViews' not applicable to local variable butterknife

    public class LoginActivity extends AppCompatActivity {

  @BindViews(value = {R.id.logo, R.id.first, R.id.second, R.id.last})
  protected List<ImageView> sharedElements;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    @BindViews({R.id.pager)

    @BindViews(R.id.scrolling_background)
    final AnimatedViewPager pager = ButterKnife.findById(this, R.id.pager);
    final ImageView background = ButterKnife.findById(this, R.id.scrolling_background);
    int[] screenSize = screenSize();

    for (ImageView element : sharedElements) {
      @ColorRes int color = element.getId() != R.id.logo ? R.color.white_transparent : R.color.color_logo_log_in;
      DrawableCompat.setTint(element.getDrawable(), ContextCompat.getColor(this, color));
    }

authfragment

{
    public abstract class AuthFragment extends Fragment {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
      }
      protected Callback callback;
    
      @BindView(R.id.caption)
      protected VerticalTextView caption;
    
      @BindView(R.id.root)
      protected ViewGroup parent;
    
      protected boolean lock;
    
    
    
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(authLayout(), container, false);
        ButterKnife.bind(this, root);
        KeyboardVisibilityEvent.setEventListener(getActivity(), isOpen -> {
          callback.scale(isOpen);
          if (!isOpen) {
            clearFocus();
          }
        });
        return root;
      }
    
      public void setCallback(@NonNull Callback callback) {
        this.callback = callback;
      }
    
      @LayoutRes
      public abstract int authLayout();
    
      public abstract void fold();
    
      public abstract void clearFocus();
    
      @OnClick(R.id.root)
      public void unfold() {
        if (!lock) {
          caption.setVerticalText(false);
          caption.requestLayout();
          Rotate transition = new Rotate();
          transition.setStartAngle(-90f);
          transition.setEndAngle(0f);
          transition.addTarget(caption);
          TransitionSet set = new TransitionSet();
          set.setDuration(getResources().getInteger(R.integer.duration));
          ChangeBounds changeBounds = new ChangeBounds();
          set.addTransition(changeBounds);
          set.addTransition(transition);
          TextSizeTransition sizeTransition = new TextSizeTransition();
          sizeTransition.addTarget(caption);
          set.addTransition(sizeTransition);
          set.setOrdering(TransitionSet.ORDERING_TOGETHER);
          caption.post(() -> {
            TransitionManager.beginDelayedTransition(parent, set);
            } 

请帮我用 butterknife 修复这个错误。 findbyid 也不可用 无法使用 bindview 请帮助提供文档或您的代码。所以这就是 authFragment 现在按照 GermliShx 的建议进行了一些更改,这些错误可能是我的实现错误所以请帮助我。这是带有一些动画的登录页面 idk y butterknife 正在给她制造问题。我尝试解决它但运气不好这个错误是由于黄油刀的错误实施所以请帮助我

首先删除这个:

    @BindViews({R.id.pager)
    @BindViews(R.id.scrolling_background)
... 
final AnimatedViewPager pager = ButterKnife.findById(this, R.id.pager);
    final ImageView background = ButterKnife.findById(this, R.id.scrolling_background);

第二次添加:

    public class LoginActivity extends AppCompatActivity {
        ...
       //binding is declared outside OnCreate / any other function

       //your case
        @BindView(R.id.pager)
            AnimatedViewPager pager;
            @BindView(R.id.scrolling_background)
            ImageView background ;

        ..
        //then in code just use declared pager and background when needed 
         @Override
          protected void onCreate(Bundle savedInstanceState) {
              background .setColorFilter (R.color.black); //example 
        }

应该可以,但我不确定 AnimatedViewPager 是什么。

它也可能会显示 Resource IDs will be non-final in Android Gradle Plugin version 7.0, avoid using them as annotation attributes 警告,但您可以将其抑制。

尝试并回复进展如何。