我希望我的旋转器能够位于工具栏中菜单的旁边(在菜单左侧),但目前旋转器出现在菜单下方。我是否需要在onCreateOptionsMenu(Menu menu)
中添加它?
我的活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
Spinner spinner = (Spinner) findViewById(R.id.travelType_spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.travelType_array, R.layout.spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
if (spinner != null) {
spinner.setAdapter(adapter);
}
布局:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<Spinner
android:id="@+id/travelType_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
Spinner_item.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/whiteText"
android:textStyle="bold"
android:padding="15dp"/>