无法在局部变量中使用'@BindViews'不适用于局部变量黄油刀


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);
} 

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

首先删除这个:

@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警告,但您可以直接抑制它

试着回答进展如何。

最新更新