I was implementing the Navigation Drawer standard and when I emulated the apk the options screens were over the apk home screen, like this:
MainActivity.javaFile
@OverridepublicvoidonBackPressed(){DrawerLayoutdrawer=(DrawerLayout)findViewById(R.id.drawer_layout);if(drawer.isDrawerOpen(GravityCompat.START)){drawer.closeDrawer(GravityCompat.START);}else{super.onBackPressed();}}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.getMenuInflater().inflate(R.menu.menu_main,menu);returntrue;}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){//Handleactionbaritemclickshere.Theactionbarwill//automaticallyhandleclicksontheHome/Upbutton,solong//asyouspecifyaparentactivityinAndroidManifest.xml.intid=item.getItemId();//noinspectionSimplifiableIfStatementif(id==R.id.action_second_activity){returntrue;}returnsuper.onOptionsItemSelected(item);}@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
FragmentManager fragmentManager = getFragmentManager();
if (id == R.id.servic) {
} else if (id == R.id.nav_camera) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Cronograma())
.commit();
} else if (id == R.id.nav_gallery) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Localizacao())
.commit();
} else if (id == R.id.nav_share) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Sobre_aplicativo())
.commit();
} else if (id == R.id.nav_manage) {
finish();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
My fragment:
public class Localizacao extends Fragment {
View view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.local, container, false);
return view;
}
}
Why is it overriding the other intent and not changing?
I noticed that in the code it shows me these messages:
Content_main.xmlfile
<?xmlversion="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
Activity_main_drawer file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/servic"
android:icon="@drawable/servico"
android:title="Serviços" />
<item
android:id="@+id/nav_camera"
android:icon="@drawable/pref"
android:title="o local" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/local"
android:title="Localização" />
</group>
<item android:title="Informações">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/dev"
android:title="Sobre o aplicativo" />
<item
android:id="@+id/nav_manage"
android:icon="@drawable/exit"
android:title="Sair" />
</menu>
</item>
</menu>