1

Hi im working with custom dialog in android, my code:

public void generarDialogoParametros(String titulo, boolean llamaNumero) {
    Dialog dialogo = new Dialog(context,R.style.AlertDialogTheme);
    dialogo.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialogo.setContentView(R.layout.dialogo_parametros);
    dialogo.setTitle(titulo);
    TextView spo2 = (TextView) dialogo.findViewById(R.id.editTextSPO2);
    TextView pulsobajo = (TextView) dialogo.findViewById(R.id.editTextPulsoAlto);
    TextView pulsoalto = (TextView) dialogo.findViewById(R.id.editTextPulsoBajo);
    Button guardar = (Button) dialogo.findViewById(R.id.btnAceptarParametros);
    Button cancelar = (Button) dialogo.findViewById(R.id.btnCancelarParametros);
    spo2.setText(preferencias.getSPO2() + "");
    pulsoalto.setText(preferencias.getPulsoAlto() + "");
    pulsobajo.setText(preferencias.getPulsoBajo() + "");
    guardarParametrosNuevos(guardar,cancelar, dialogo, spo2, pulsoalto, pulsobajo, llamaNumero);
    dialogo.show();
    dialogo.setCancelable(false);
}

in android 4,5,6 works like:

enter image description here

But in 7+

enter image description here

I dont know, how i'm fix it can help me?

Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
Daniel ORTIZ
  • 2,488
  • 3
  • 21
  • 41
  • I faced same Problem before 2 days. In my case, I used Linear Layout as Parent Layout, I fixed it correct by Using RelativeLayout instead of Linear Layout. You can try this. Hope this help you. – Bhoomika Patel Nov 13 '17 at 04:48
  • @BhoomikaPatel may be you are right but but it can also achieve using **`Window`** to set width and hight programatically of dialog – Goku Nov 13 '17 at 04:54
  • Refer this Link: https://stackoverflow.com/questions/1362723/how-can-i-get-a-dialog-style-activity-window-to-fill-the-screen – Bhoomika Patel Nov 13 '17 at 04:55
  • @Prem Yes you can, But in most of cases it is not working. Thats why i gave you this solution. :) – Bhoomika Patel Nov 13 '17 at 04:56
  • **But in most of cases it is not working** it working in all cases @BhoomikaPatel – Goku Nov 13 '17 at 04:57

1 Answers1

1

Try this set hight and width of your dialog programatically using below code

    public void generarDialogoParametros(String titulo, boolean llamaNumero) {
            Dialog dialogo = new Dialog(context,R.style.AlertDialogTheme);
            dialogo.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialogo.setContentView(R.layout.dialogo_parametros);
            Window window = dialogo.getWindow();
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            window.setGravity(Gravity.CENTER);
            dialogo.setTitle(titulo);
            TextView spo2 = (TextView) dialogo.findViewById(R.id.editTextSPO2);
            TextView pulsobajo = (TextView) dialogo.findViewById(R.id.editTextPulsoAlto);
            TextView pulsoalto = (TextView) dialogo.findViewById(R.id.editTextPulsoBajo);
            Button guardar = (Button) dialogo.findViewById(R.id.btnAceptarParametros);
            Button cancelar = (Button) dialogo.findViewById(R.id.btnCancelarParametros);
            spo2.setText(preferencias.getSPO2() + "");
            pulsoalto.setText(preferencias.getPulsoAlto() + "");
            pulsobajo.setText(preferencias.getPulsoBajo() + "");
            guardarParametrosNuevos(guardar,cancelar, dialogo, spo2, pulsoalto, pulsobajo, llamaNumero);
            dialogo.show();
            dialogo.setCancelable(false);
        }
Goku
  • 9,102
  • 8
  • 50
  • 81