3
我使用AppCompat庫中的新工具欄組件。我試圖在我的工具欄上顯示動作按鈕,但他們從不顯示。Android工具欄沒有顯示的動作按鈕
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_login"
android:title="@string/action_login"
android:orderInCategory="100"
app:showAsAction="ifRoom" />
</menu>
我的活動
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
toolbar, R.string.drawer_open, R.string.drawer_close);
toolbar.setTitle(R.string.title_activity_posts);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
if (getSupportActionBar() != null)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
actionBarDrawerToggle.syncState();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
我缺少什麼?
確實如此。我缺少'setSupportActionBar(toolbar);' – Andrei