2
我有兩個工具欄(頂部和底部),如圖所示:的Android,在工具欄的佈局位置菜單項
兩個工具欄在自己的XML文件中定義的,沒有什麼特別的:
top_toolbar.xlm
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
bottom_toolbar.xlm
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorBottomTrans"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
,並加入到主要活動:
activity_main.xlm
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayout"
android:background="@android:color/white">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></include>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:layout_below="@+id/tool_bar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="20dp" />
<include
android:id="@+id/tool_bar_bottom"
layout="@layout/tool_bar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></include>
</RelativeLayout>
其中每個工具欄上的項目是從菜單文件膨脹。
MainActivity
private void initToolbars() {
topToolbar = (Toolbar) findViewById(R.id.tool_bar);
bottomToolbar = (Toolbar) findViewById(R.id.tool_bar_bottom);
setSupportActionBar(topToolbar);
bottomToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_item_1:
break;
}
return true;
}
});
bottomToolbar.inflateMenu(R.menu.menu_main);
bottomToolbar.getBackground().setAlpha(125);
}
但是我希望做的是移動 「項目1」 底部工具欄左側,如圖所示:
有一種方法來做到這一點?
在此先感謝。