2017-11-24 31 views
1

Yup dies wird mehrere Möglichkeit gefragt, aber keiner der Methode funktioniert.Machen Sie Dialog-Breite auf den Vollbildmodus

Ich versuche, die Dialogbreite auf Vollbild auszugeben.

Dialog Layout:

<?xml version="1.0" encoding="utf-8"?> 

    <android.support.constraint.ConstraintLayout 
    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/constraint_layout" 
     android:layout_width="match_parent" 
     android:layout_height="300dp"> 

     <android.support.constraint.Guideline 
      android:id="@+id/guideline3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      app:layout_constraintGuide_percent="0.08" /> 

     <TextView 
      android:fontFamily="@font/gotham_medium_regular" 
      android:textAllCaps="true" 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp" 
      android:text="Login" 
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Large" 
      android:textStyle="bold" 
      app:layout_constraintStart_toStartOf="@+id/guideline3" 
      app:layout_constraintTop_toTopOf="parent" /> 

     <TextView 
      android:fontFamily="@font/gotham_light" 
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
      android:layout_marginTop="8dp" 
      app:layout_constraintStart_toStartOf="@+id/guideline3" 
      app:layout_constraintTop_toBottomOf="@+id/textView6" 
      android:id="@+id/textView7" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Enter your phone number to proceed" /> 

     <android.support.design.widget.TextInputLayout 
      android:id="@+id/text_input" 
      android:layout_marginTop="24dp" 
      android:layout_width="0dp" 
      app:layout_constraintTop_toBottomOf="@+id/textView7" 
      android:layout_height="wrap_content" 
      app:layout_constraintEnd_toEndOf="@+id/guideline4" 
      app:layout_constraintStart_toStartOf="@+id/guideline3"> 

      <android.support.design.widget.TextInputEditText 
       android:id="@+id/userPhone" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fontFamily="@font/gotham_light" 
       android:hint="PHONE NUMBER" 
       android:inputType="phone" 
       android:text="+91" /> 
     </android.support.design.widget.TextInputLayout> 



     <android.support.constraint.Guideline 
      android:id="@+id/guideline4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      app:layout_constraintGuide_percent="0.92" /> 


     <Button 
      android:layout_marginBottom="@dimen/activity_horizontal_margin" 
      android:id="@+id/continueButton" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/button_background" 
      android:fontFamily="@font/gotham_light" 
      android:text="Continue" 
      android:textColor="@android:color/white" 
      app:layout_constraintEnd_toEndOf="@+id/guideline4" 
      app:layout_constraintStart_toStartOf="@+id/guideline3" 
      app:layout_constraintTop_toBottomOf="@+id/text_input" /> 


    </android.support.constraint.ConstraintLayout> 

Dialog Code:

val dialogBuilder = AlertDialog.Builder(ContextThemeWrapper(context,R.style.ThemeDialog)) 
     val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater 
     val dialogView = inflater.inflate(R.layout.mobile_bottom_sheet_layout, null) 

     val phone = dialogView.findViewById<EditText>(R.id.userPhone) 
     dialogBuilder.setView(dialogView) 
     val alertDialog = dialogBuilder.create() 

     val countinueButton = dialogView.findViewById<Button>(R.id.continueButton) as Button 

     countinueButton.setOnClickListener { 

      if(phone.text.toString().isEmpty()){ 
       phone.error=getString(R.string.empty) 
       phone.requestFocus() 
      }else if(phone.text.toString().length!=13){ 
       phone.error=getString(R.string.phone_length_error) 
       phone.requestFocus() 
      }else{ 

       checkIfTrainerExists(phone.text.toString(),[email protected]); 
      } 

     } 

     alertDialog.show() 

Dinge, die ich versucht habe:

  1. https://stackoverflow.com/a/28519059/1640009
  2. https://stackoverflow.com/a/2680670/1640009
  3. https://stackoverflow.com/a/6631310/1640009

Ich habe die anderen Lösungen auch ausprobiert. Aber keiner funktioniert.

+0

haben Sie versucht, diese https://stackoverflow.com/a/40718796/8112541 – Prem

+0

ja @ Prem. Aber es hat auch nicht funktioniert –

+0

machen Sie Ihre ** 'ConstraintLayout' ** Höhe zu **' Android: layout_width = "match_parent" android: layout_height = "match_parent" '** – Prem

Antwort

2

Sie können eine benutzerdefinierte FragmentDialog erstellen und tun

@Override 
public void onResume() { 
    // Resize the dialog to full screen. 
    if (getDialog() != null && getDialog().getWindow() != null) { 
     Window window = getDialog().getWindow(); 
     window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); 
    } 
    super.onResume(); 
} 

Tutorials für FragmentDialogs:

+0

Nein Ich möchte dies WEG machen. –

+2

Fein. Aber vertrau mir, komplexe Dialoge sollten besser 'FragmentDialogs' sein.Dann könnten Sie den Dialog wiederverwenden, einige Validierungen für Ihre Textfelder durchführen und den Lebenszyklus besser steuern. – noongiya95

0

Versuchen Dialog stattmit, so können Sie Ihre benutzerdefinierten Dialoge nach Belieben erstellen.

auch Sie davon kann:

public class CustomDialog extends Dialog{ 

    public void onCreate(Bundle savedInstance) { 

     super.onCreate(savedInstance); 

     setContenctView(R.layout.custom_layout); 

     // You can manipulate the Dialog using   
     //Window window = getDialog().getWindow(); 


    }  

} 
1

Versuchen Sie, diese

benutzerdefinierte Dialogkomponente unter Code

import android.app.Dialog; 
import android.content.Context; 
import android.os.Bundle; 
import android.support.annotation.NonNull; 

public class CustomDialog extends Dialog { 

    public CustomDialog(@NonNull Context context) { 
     super(context); 
    } 

    public CustomDialog(@NonNull Context context, int themeResId) { 
     super(context, themeResId); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.dialog_layout);// use your layout in place of this. 

    } 
} 

schreiben Stellen, wo Sie wollen.

CustomDialog dialog=new CustomDialog(MainActivity.this, android.R.style.Theme_Material_Light_NoActionBar_Fullscreen); 
       dialog.show(); 

Screenshot

Verwandte Themen