0
如果我按菜單鍵,它會在我所有的應用程序的活動中觸發兩次 我試圖覆蓋onKeyUp和onKeyDown,但沒有使用任何建議,爲什麼會發生這種情況?在此先感謝代碼這樣下去..菜單鍵被觸發兩次android
public class MainActivity extends ActionBarActivity {
private MainActivityDrawer mainActivityDrawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mainActivityDrawer = (MainActivityDrawer) getSupportFragmentManager().findFragmentById(R.id.fragment_main_activity_drawer_in);
mainActivityDrawer.setUp(R.id.fragment_main_activity_drawer_in, (DrawerLayout) findViewById(R.id.mainDrawer1), toolbar);
new clicklisteners().execute();
DrawerLayout drawerLayout = ((DrawerLayout) (findViewById(R.id.mainDrawer1)));
drawerLayout.setStatusBarBackground(R.color.PrimaryColorDark);
registerReceiver(err, new IntentFilter("ERROR_LOG_BUTTON_CLICKED"));
//toolbar.setOnKeyListener(this);
}
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(event.getAction()==KeyEvent.ACTION_UP)
{
if(event.getKeyCode()==KeyEvent.KEYCODE_MENU)
{
ShowToast("Hello");
return true;
}
}
if(event.getKeyCode()==KeyEvent.KEYCODE_BACK)
{
if(mainActivityDrawer.isOpened())
{
mainActivityDrawer.close();
}
else
{
finish();
}
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
......
}
請給我們展示一些代碼。問模糊的問題是沒有幫助的。 – 2015-04-05 17:57:29
我發佈了我的MainActivity的代碼 – 2015-04-05 18:09:07
這是什麼:'new clicklisteners()。execute();' – sschrass 2015-04-05 18:58:52