我有一个CoordinatorLayout在那里我有我的按钮:Butterknife不与作品还包括标签
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/icon"
app:fabSize="normal"/>
</android.support.design.widget.CoordinatorLayout>
然后,我有活动的XML,其中包括我的按钮:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
<include
android:id="@+id/fabHere"
layout="@layout/fab_here"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
在这里,我有一个片段与Butterknife:
public class MyFragment extends Fragment {
....
@BindView(R.id.fab) FloatingActionButton fab;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.my_fragment, container, false);
ButterKnife.bind(this, view);
return view;
}
...
}
但如果我启动应用程序,这似乎:
java.lang.IllegalStateException:未找到字段'fabHere'的ID为2131624072的'fab'所需的视图。如果此视图是可选的,则添加'@Nullable'(fields)或'@Optional'(方法)注释。
我试图加入 '@Nullable' 和 '@optional' 注解,但它不工作
如果您删除'android:id =“@ + id/fabHere”'会发生什么? – Blackbelt
什么都没有发生 –
你的意思是什么都没有发生?它会不会崩溃,它不显示任何内容吗?使用'Butterknife.setDebug(true)' –