gpt4 book ai didi

java - 如何删除注入(inject)的 View ?

转载 作者:太空狗 更新时间:2023-10-29 13:57:23 25 4
gpt4 key购买 nike

我有以下布局,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 进行注入(inject)的代码:

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 的布局中删除绑定(bind) View 。

注意事项:使用 ButterKnife 绑定(bind) View 意味着您在 main activity 中具有绑定(bind)代码的布局中的 View .所以应该有一个代码:

@BindView(R.id.your_view_in_include_button) View yourViewName;

根据“包含布局”中的 View 删除它。然后重建您的应用。

建议:
将您的 ButterKnife 升级到当前版本。

关于java - 如何删除注入(inject)的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38387436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com