菜单键被触发两次android

时间:2015-04-05 17:56:33

标签: android

如果我按下菜单键,则会在我的所有应用活动中触发两次 我试图覆盖onKeyUp和onKeyDown,但没有使用任何建议,为什么会发生这种情况?在此先感谢代码继续这样..

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);
    }
    ......
}

1 个答案:

答案 0 :(得分:0)

似乎库'com.android.support:appcompat-v7:22.0.0'菜单按钮有问题,当我将v7:22.0.0改为v7:21.0.0时,菜单键正常工作