集成 Butterknife 后未显示菜单项
Menu Items not shown After Integrating Butterknife
在我当前的 Android 项目中,我使用 Butterknife 库来绑定视图并为它们使用 onClick 注释。这一切即使在片段中也能很好地工作,但现在我无法找到集成 ButterKnife 之前未看到的 solution:Problem。现在菜单项和应用程序名称在我 application.I 中使用 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" />
使用
解决了
//在projectGradle中编译这个
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//在appGradle中
apply plugin: 'android-apt'
这可能是一个愚蠢的错误,但我很高兴我解决了它。
在我当前的 Android 项目中,我使用 Butterknife 库来绑定视图并为它们使用 onClick 注释。这一切即使在片段中也能很好地工作,但现在我无法找到集成 ButterKnife 之前未看到的 solution:Problem。现在菜单项和应用程序名称在我 application.I 中使用 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" />
使用
解决了//在projectGradle中编译这个
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//在appGradle中
apply plugin: 'android-apt'
这可能是一个愚蠢的错误,但我很高兴我解决了它。