1
I was implementing the standard Navigation Drawer and when I emulated the apk was the screens of the options above the initial screen of the apk, this way:
Mainactivity.java file.
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_second_activity) {
return true;
}
return super.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 faith:
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;
}
}
Because it’s superimposing on another Intent and not changing?
I observed that in the code it shows me these messages:
content_main.xml file
<?xml version="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>
from what I’m seeing you put a
listview
along with a@id/content_frame
what’s wrong! since you will use this file(screen)content_main.xml
to make the transition from Fragments? correct?– user28366
Check out this post, where I teach how to transition between screens http://answall.com/questions/119551/menu-de-3-pontos-em-todas-activities-com-o-padr%C3%A3o-navigation-Drawer/119561#119561
– user28366
this one of yours
listview
should disappear, or you should put these items in the default menu Navigation Drawer - inactivity_main_drawer.xml
, or create a menu of items in another Fragment and call this Fragment through the@+id/content_frame
and make the transition of the screens!– user28366