Buenos días muchachos, se me ha presentado este detalle, al cargar un fragment en el contenido principal de mi app con Navigation Drawer se muestra un espacio en blanco entre el fragment y la toobar, al principio pensé que se debía modificar android:theme="@style/AppTheme.NoActionBar", cuando lo hice al mirar la vista previa ya no se muestra la toolbar en cada fragmento pero al compilar se sigue mostrando este espacio, esto sucede con todos los fragments.
A continuación comparto el código de unos de los Fragments, el layout xml, el manifest y una imagen de ilustración, muchas gracias por su ayuda.
public class Fragment_Home extends Fragment {
public Fragment_Home() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_home, container, false);
String url="http://www.uniagustiniana.edu.co/";
WebView view=(WebView) v.findViewById(R.id.wv_home);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient());// Agregamos un WebViewCliente, esto permite que se sigan ejecutando los links dentro de este WebView
view.loadUrl(url);
return v;
}
}
fragment_home.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tecnologias.uniagustapp.fragmentos.Fragment_Home">
<!-- TODO: Update blank fragment layout -->
<WebView
android:id="@+id/wv_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.tecnologias.uniagustapp.MainActivity"
tools:showIn="@layout/app_bar_main">
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,Portal.OnFragmentInteractionListener, Biblioteca.OnFragmentInteractionListener, Evu.OnFragmentInteractionListener,
Siga.OnFragmentInteractionListener, Moodle.OnFragmentInteractionListener, Facebook.OnFragmentInteractionListener,
Twitter.OnFragmentInteractionLiastener, LinkedIn.OnFragmentInteractionListener, GooglePlus.OnFragmentInteractionListener, Flickr.OnFragmentInteractionListener,
Tour.OnFragmentInteractionListener, Instagram.OnFragmentInteractionListener, Youtube.OnFragmentInteractionListener, Noticias.OnFragmentInteractionListener,
Home.OnFragmentInteractionListener, Whatsapp.OnFragmentInteractionListener, Lista_DirectorioFragment.OnFragmentInteractionListener {
//Bottom
private BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);//Los iconos del menu lateral toman su color original
//BOTTON NAVIGATION VIEW
final Fragment home = new Home();
final Fragment noticias = new Noticias();
final Fragment calendario = new Calendario();
final Fragment ubicacion = new Map_Fragment();
final Fragment pqrs = new PQRS();
final Fragment preinscrip = new PreInscripcion();
//FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
//fragmentTransaction.replace(R.id.content_main, home).commit();
//FragmentManager fragmentManager = getSupportFragmentManager();
//fragmentManager.beginTransaction().replace(R.id.content_main, new Home()).commit();
if(savedInstanceState == null) {
//FragmentManager fragmentManager = getSupportFragmentManager();
//fragmentManager.beginTransaction().replace(R.id.content_main, new Home()).commit();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_main, new Home()).commit();
}
bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
bottomNavigationView.setItemIconTintList(null);//Los iconos del menu Bottom toman su color original
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentManager fragmentManager = getFragmentManager();
if (item.getItemId() == R.id.noticias) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main, noticias).commit();
} else if (item.getItemId() == R.id.rutas) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main, ubicacion).commit();
} else if (item.getItemId() == R.id.cal_aca) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main, calendario).commit();
} else if (item.getItemId() == R.id.pqrs) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main, pqrs).commit();
} else if (item.getItemId() == R.id.preinscripcion) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main, preinscrip).commit();
}
return true;
}
});
}
@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.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_home) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
boolean FragmentTransaction = true;
Fragment fragment = null;
if (id == R.id.nav_home) {
fragment = new Home();
FragmentTransaction = true;
} else if (id == R.id.nav_portal) {
fragment = new Portal();
FragmentTransaction = true;
} else if (id == R.id.nav_biblioteca) {
fragment = new Biblioteca();
FragmentTransaction = true;
} else if (id == R.id.nav_evu) {
fragment = new Evu();
FragmentTransaction = true;
} else if (id == R.id.nav_directorio) {
//fragment = new Directorio();
//fragment = new Directorio_Lista();
fragment = new Lista_DirectorioFragment();
FragmentTransaction = true;
} else if (id == R.id.nav_siga) {
fragment = new Siga();
FragmentTransaction = true;
} else if (id == R.id.nav_moodle) {
fragment = new Moodle();
FragmentTransaction = true;
} else if (id == R.id.nav_face) {
fragment = new Facebook();
FragmentTransaction = true;
} else if (id == R.id.nav_twitter) {
fragment = new Twitter();
FragmentTransaction = true;
} else if (id == R.id.nav_in) {
fragment = new LinkedIn();
FragmentTransaction = true;
} else if (id == R.id.nav_flk) {
fragment = new Flickr();
FragmentTransaction = true;
} else if (id == R.id.nav_youtube) {
fragment = new Youtube();
FragmentTransaction = true;
} else if (id == R.id.nav_gplus) {
fragment = new GooglePlus();
FragmentTransaction = true;
} else if (id == R.id.nav_inst) {
fragment = new Instagram();
FragmentTransaction = true;
} else if (id == R.id.nav_round) {
//fragment = new Tour();
//FragmentTransaction = true;
FragmentTransaction = false;
Intent a = new Intent(MainActivity.this, Prueba_Tour.class);
startActivity(a);
} else if (id == R.id.nav_preguntas) {
fragment = new Preguntas();
FragmentTransaction = true;
} else if (id == R.id.nav_wtsp) {
fragment = new Whatsapp();
FragmentTransaction = true;
} else if (id == R.id.nav_game) {
//No abre un fragmento, abre una actividad que tiene contenido un juego en html, css y js
//fragment = new Home();
FragmentTransaction = false;
//Intent i = new Intent(MainActivity.this, Entretenimiento.class);
Intent i = new Intent(MainActivity.this, VirtualApoyo.class);
//Intent i = new Intent(MainActivity.this, Virtuaidad.class);
startActivity(i);
}
if(FragmentTransaction){
getFragmentManager().beginTransaction()
.replace(R.id.content_main, fragment)
.commit();
item.setChecked(true);
getSupportActionBar().setTitle(item.getTitle());
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onFragmentInteraction(Uri uri) {
}
}
Hago referencia al espacio encerrado en rojo :