我一直在努力将新的appcompat-v7:21.0.0添加到我的项目中。出于某种原因,我的操作栏上的溢出菜单在打开时决定重叠我的操作栏。它应该在操作栏下面打开。
这是我的基本布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<RelativeLayout
android:id="@+id/top_status"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_gravity="top|center"
android:background="@color/message_bottom_background"
android:gravity="center_horizontal"
tools:ignore="UselessParent"
android:visibility="gone">
<ImageView
android:id="@+id/top_warning_thumb"
android:src="@drawable/ic_action_warning"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/top_warning_thumb_desc"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:visibility="gone"/>
<TextView
android:id="@+id/top_warning_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/test_text_shortest"
android:layout_toEndOf="@id/top_warning_thumb"
android:layout_toRightOf="@id/top_warning_thumb"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textSize="20sp"
android:textColor="@color/theme_primary_background"
android:layout_marginTop="1sp"
/>
</RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:background="@color/card_background">
<TextView
android:id="@+id/left_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textSize="25sp"
android:lineSpacingExtra="5sp"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/test_text_shortest"
android:paddingLeft="0sp"
android:paddingRight="0sp"
android:textColor="@color/card_background"
/>
<ListView android:id="@+id/left_drawer_child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/transparent"
android:dividerHeight="1dp"
android:paddingLeft="0sp"
android:paddingRight="0sp" />
</LinearLayout>
<!--android:divider="#666"-->
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
以下是我的主要活动中与菜单有关的代码:
public class MainActivity extends ActionBarActivity implements WifiDiagnosticFragment
.OnFragmentInteractionListener,DispatchFragment.OnFragmentInteractionListener,
TextMessageViewerFragment.OnFragmentInteractionListener,
SupervisorFragment.OnFragmentInteractionListener,
WorklistFragment.OnFragmentInteractionListener, Observer {
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.base_menu, menu);
if (BuildConfig.BUILD_TYPE.equals("debug")){
menu.findItem(R.id.device_admin).setVisible(true);
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns true,
// then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
switch (item.getItemId()) {
case R.id.help:
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
HelpDialog helpDialog = new HelpDialog();
helpDialog.show(fm,"Help");
return true;
case R.id.device_admin:
fm = getSupportFragmentManager();
AdminDialog adminDialog = new AdminDialog();
adminDialog.show(fm,"Device Admin");
return true;
default:
return super.onOptionsItemSelected(item);
}
//return super.onOptionsItemSelected(item);
}
}