Android动作溢出在ActionBar之上绘制

时间:2015-01-28 12:58:44

标签: java android

为了在我的应用程序中使用ActionBar,我的主要活动扩展自android.support.v7.app.ActionBarActivity。这是它的外观:

enter image description here

但是,当我单击溢出操作按钮时,选项会显示在ActionBar上:

enter image description here

我想在ActionBar下显示溢出菜单,就像它应该的那样。我该如何解决这个问题?

我正在运行Android 4.4(KITKAT)。如果您需要更多细节,请询问。感谢。

以下是我主要活动的代码:

public class SendMessageActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_send_message);

        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setLogo(R.drawable.ic_action_bar_icon);
        getSupportActionBar().setDisplayUseLogoEnabled(true);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.activitySendMessage, new SendMessageFragment())
                    .commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_activity_send_message, menu);
        return true;
    }

    @Override
    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.actionSettings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }

        if (id == R.id.actionShowHistory) {
            startActivity(new Intent(this, SentMessagesHistoryActivity.class));
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

0 个答案:

没有答案