我目前正在创建一个Android应用程序,其中包含一个移动到屏幕底部的工具栏,作为“切换场景”菜单。
screenshot
我想做的是调整工具栏,使其垂直显示在右下角(而不是水平),如
this
<android.support.v7.widget.Toolbar
android:id="@+id/menuToolbar"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|right"
android:background="?attr/colorPrimary"
android:elevation="15dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
然后在OnCreate()方法中调用initToolbar()。
private void initToolbar() {
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.menuToolbar);
toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()){
case R.id.action_addPoi:
Intent addPoi = new Intent(MainActivity.this, AddPoi.class);
startActivity(addPoi);
break;
case R.id.action_calendar:
Intent calen = new Intent(MainActivity.this, Calendar.class);
startActivity(calen);
break;
}
return true;
}
});
// Inflate a menu to be displayed in the toolbar
toolbarBottom.inflateMenu(R.menu.menumain);
}