工具栏菜单项在android 4.4(19)上不可点击



我有一个适用于Android sdk版本23的Android应用程序。现在,我尝试让用户可以使用19到23版本。除了应用程序头部的工具栏外,一切都很好。我无法单击菜单项。我点击时什么也没发生。此外,如果我插入Log.v(),则调试视图中没有消息。

我能做什么?

public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        if (id == R.id.action_refresh) {
            doRefreshGames(item);
            return true;
        }
        if(id == R.id.action_rss){
            Intent rssIntent = new Intent(AmericanFootball.this, AmericanFootballRSS.class);
            //if you need to pass data:
            Bundle mBundle = new Bundle();
            mBundle.putString("myKey", "comeon");
            rssIntent.putExtras(mBundle);
            startActivity(rssIntent);
        }
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

我也遇到过这个问题。这是因为我使用的是CoordinatorLayout,它是一个超级强大的FrameLayout,因此覆盖了工具栏,从而阻止了与工具栏的交互。我通过用LinearLayout替换CoordinatorLayout并使其具有垂直方向来解决这个问题。您也可以通过设置相对于父级的toolbar位置来解决此问题,如这里所述

最新更新