在我目前的Android项目中,我使用Butterknife库来绑定视图并使用onClick注释。这一切在片段中都很有效但现在我无法找到解决方案:在整合ButterKnife之前没有看到问题。现在菜单项和应用程序名称在我的应用程序中使用Butterknife后消失。我是androidButterKnife.Anyone的新手可以建议我如何处理这个?在此先感谢。
package com.example.niroj.firstscreen;
import android.content.DialogInterface;
import android.content.Intent;;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity implements SearchView.OnQueryTextListener {
@BindView(R.id.search)
MenuItem searchitem;
@BindView(R.id.fab1)
FloatingActionButton floatingActionButton;
@BindColor(R.color.colorFolatingButton)
int Floating_Button_Color;
@BindView(R.id.toolbar)
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
}
@OnClick(R.id.fab1)
public void newForm (View view){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Confirm");
builder.setMessage("Are you sure?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getApplicationContext(),BuilderPage.class);
startActivity(intent);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
// display menu incons from menu_main XML
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.frontscreen, menu);
MenuItem searchitem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchitem);
searchView.setOnQueryTextListener(this);
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
}
我的菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="hint_search"
android:icon="@drawable/ic_magnify"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView" />
答案 0 :(得分:2)
使用
解决了//在projectGradle中编译它
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//在appGradle中
apply plugin: 'android-apt'
这可能是一个愚蠢的错误,但我很高兴我解决了它。