如何删除注入的视图?
How to remove view that is injected?
我有以下布局,activity_main.xml
:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.lorentzos.flingswipe.SwipeFlingAdapterView
android:id="@+id/frame"
android:background="#d1d1d1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rotation_degrees="15.5"
tools:context=".MainActivity"
android:layout_gravity="top"/>
<TextView
android:id="@+id/tv_noJobsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#474747"
android:textAlignment="center"
tools:text="Nothing Left to Swipe!"
android:layout_gravity="center" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include layout="@layout/buttons" />
</merge>
在我的 main activity
中,我有以下使用 ButterKnife
进行注入的代码:
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
我想删除布局的 <include>
部分,因为我不再需要这些按钮,但是,当我删除 <include>
行时,出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lorentzos.swipecards.example/com.lorentzos.swipecards.MainActivity}: java.lang.RuntimeException: Unable to inject views for com.lorentzos.swipecards.MainActivity@f356341
我做错了什么?
有什么原因导致我无法删除 <include>
?
编辑:
@InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//color the notification bar with our company colors
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.laborswipe_notificationbar));
//remove title from action bar and add the logo to the top left of the action bar
setUpActionBar();
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
删除 <include layout=.../>
后,还要从 activity 中的布局中删除绑定视图。
备注:
使用 ButterKnife
绑定视图意味着您在布局中的视图具有 main activity
中的绑定代码。所以应该有一个代码:
@BindView(R.id.your_view_in_include_button) View yourViewName;
根据您的“包含布局”中的视图删除它。
然后重建您的应用程序。
建议:
将您的 ButterKnife 升级到当前版本。
我有以下布局,activity_main.xml
:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.lorentzos.flingswipe.SwipeFlingAdapterView
android:id="@+id/frame"
android:background="#d1d1d1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rotation_degrees="15.5"
tools:context=".MainActivity"
android:layout_gravity="top"/>
<TextView
android:id="@+id/tv_noJobsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#474747"
android:textAlignment="center"
tools:text="Nothing Left to Swipe!"
android:layout_gravity="center" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include layout="@layout/buttons" />
</merge>
在我的 main activity
中,我有以下使用 ButterKnife
进行注入的代码:
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
我想删除布局的 <include>
部分,因为我不再需要这些按钮,但是,当我删除 <include>
行时,出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lorentzos.swipecards.example/com.lorentzos.swipecards.MainActivity}: java.lang.RuntimeException: Unable to inject views for com.lorentzos.swipecards.MainActivity@f356341
我做错了什么?
有什么原因导致我无法删除 <include>
?
编辑:
@InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//color the notification bar with our company colors
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.laborswipe_notificationbar));
//remove title from action bar and add the logo to the top left of the action bar
setUpActionBar();
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
删除 <include layout=.../>
后,还要从 activity 中的布局中删除绑定视图。
备注:
使用 ButterKnife
绑定视图意味着您在布局中的视图具有 main activity
中的绑定代码。所以应该有一个代码:
@BindView(R.id.your_view_in_include_button) View yourViewName;
根据您的“包含布局”中的视图删除它。 然后重建您的应用程序。
建议:
将您的 ButterKnife 升级到当前版本。