Estava implementando o padrão Navigation Drawer e quando emulei o apk ficou as telas das opções por cima da tela inicial do apk, desse jeito:
Arquivo MainActivity.java
@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;
}
Meu 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;
}
}
Porque esta sobrepondo a outra intent e não mudando?
observei que no código ele me mostra essas mensagens:
Arquivo content_main.xml
<?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>
Arquivo activity_main_drawer:
<?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>
listview
junto com um@id/content_frame
o que está errado! já que você irá usar este arquivo(tela)content_main.xml
para fazer a transição dos fragments? correto?listview
deve desaparecer, ou você deve colocar esses itens no menu do padrão Navigation Drawer - emactivity_main_drawer.xml
, ou ainda criar um menu de itens em outro fragment e chamar esse fragment através do@+id/content_frame
e fazer a transição das telas!