I need something similar to DialogFragment
but with a full class, in other words, create a activity
floating%. The procedure is as follows:
In my MainActivity
pulse on a Item of my ListView
and it shows me a contextual menu I select More Information and it open my class MasInformacion
loading the data of my Sqlite
of that Item , well, with this code I have achieved that MasInformacion
is floating (maybe not the best option, if there is another you can better comment to me please) and transparent so that it shows behind my MainActivity
, like this:
link (I add the image because I fail to upload them here)
Well, I'm looking for it like this:
link (I add the image because I fail to upload them here)
That is not completely transparent, but has opacity to obscure the 'class' behind it.
MasInformacion
: So I do it "Floating"
DisplayMetrics flotante = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(flotante);
int width = flotante.widthPixels;
int height = flotante.heightPixels;
getWindow().setLayout((int)(width*.9),(int)(height*.7));
...
// Recupero los datos de la DB
extras = getIntent().getExtras();
if (estadoEditarPersona()) {
editTextNombre.setText(extras.getString("nombre"));
editTextFecha.setText(extras.getString("fecha"));
editTextZodiaco.setText(extras.getString("zodiaco"));
editTextEdad.setText(extras.getString("edad"));
editTextDiasrestantes.setText(extras.getString("diasrestantes"));
ruta_imagen = extras.getString("ruta_imagen");
imagenPersona.setImageBitmap(crearThumb());
}
}
MainActivity
// menu contextual
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.menu_contextual_mas_informacion:
masInformacion((int)info.id);
return true;
default:
return super.onContextItemSelected((android.view.MenuItem) item);
}
}
...
// metodo masInformacion
public void masInformacion(int p_id){
Persona persona;
try{
persona = baseDatos.getPersona(p_id);
// Se dirige a la actividad MasInformacion
Intent actividad_editarPersona = new Intent(this, MasInformacion.class);
// Carga los datos para mostrar en MasInformacion
actividad_editarPersona.putExtra("id", p_id);
actividad_editarPersona.putExtra("nombre", persona.getNombre());
actividad_editarPersona.putExtra("fecha", persona.getFecha());
actividad_editarPersona.putExtra("zodiaco", persona.getZodiaco());
actividad_editarPersona.putExtra("edad", persona.getEdad());
actividad_editarPersona.putExtra("diasrestantes", persona.getDiasrestantes());
actividad_editarPersona.putExtra("ruta_imagen", persona.getRutaImagen());
startActivityForResult(actividad_editarPersona, CODIGO_RESULT_EDITAR_PERSONA);
}catch (Exception e){
Toast.makeText(getApplicationContext(), (getResources().getString(R.string.error_mostrarinformacion)), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}finally{
baseDatos.cerrar();
}
}
style.xml
I charge from AndroidManifest
with android:theme="@style/AppTheme.Flotante"/>
<style name="AppTheme.Flotante">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowBackground">@drawable/borde_flotante</item>
</style>
<!-- probe así pero lo transparente se vuelve completamente negro, cuando "colorPrimary" no es negro-->
<style name="AppTheme.Flotante">
<item name="android:windowBackground">@color/colorPrimary</item>
</style>