2017-02-08 2 views
0

Ich erstelle eine Klasse erweitert DialogFragment-Klasse, mein Code ist wie folgt, mein Problem ist der Dialog versteckt unter Statusleiste (im System) und der Symbolleiste (in der Aktivität), ich beziehe mich die Frage hier DialogFragment not floating, acts embeded or as another fragment fügen Sie die onCreate Funktion hinzu und legen Sie den Stil fest, aber der Dialog bleibt nur unter der Symbolleiste verborgen, nicht wie das Tutorial sagte, es wird auf dem Aktivitätsfenster schweben.DialogFragment schwebt nicht im Aktivitätsfenster

public class PasswordDialog extends DialogFragment { 
...... 
public static PasswordDialog newInstance(PdfFragment pdfFragment) { 
    Log.i(sClassTag,"newInstance in PdfFragmentPasswordDialog"); 
    PdfFragmentPasswordDialog passwordDialog = new PdfFragmentPasswordDialog(); 
    passwordDialog.mPdfFragment = pdfFragment; 
    setInteractionListener(pdfFragment); 
    return passwordDialog; 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    // Pick a style based on the num. 
    int style = DialogFragment.STYLE_NORMAL, theme = 0; 
    setStyle(style, theme); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    Log.i(sClassTag,"onCreateView in PdfFragmentPasswordDialog"); 
    // Inflate the layout to use as dialog or embedded fragment 
    mView = inflater.inflate(R.layout.layout_password, container, false); 
    addButtonListener(); 
    addEdittextListener(); 
    return mView; 
} 

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    Log.i(sClassTag,"onCreateView in onCreateDialog"); 
    Dialog dialog = super.onCreateDialog(savedInstanceState); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    return dialog; 
} 
void showPasswordDialog(boolean isFirstTime) { 
.... 
FragmentManager fragmentManager = getActivity().getFragmentManager(); 

show(fragmentManager, "dialog"); 
... 
} 

Die Layoutdatei ist

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 
<ImageView 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:src="@drawable/ic_img_passwordkey_48" 
    android:id="@+id/key_icon" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="20dp" 
    android:contentDescription="@string/password_input_hint_message"/> 

<Space 
    android:layout_width="match_parent" 
    android:layout_height="16dp" /> 

<EditText 
    android:imeOptions="flagNoExtractUi" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textPassword" 
    android:textColorHint="@color/password_dialogUI_hint_text_color" 
    android:textColor="@color/password_dialogUI_text_color" 
    android:textSize="12sp" 
    android:hint="@string/password_input_hint_message" 
    android:ems="10" 
    android:id="@+id/dialogUI_edit_text" 
    android:textCursorDrawable="@null" 
    android:fontFamily="sans-serif" 
    android:layout_marginStart="8dp" 
    android:layout_marginEnd="8dp" 
    android:textDirection="locale"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/password_error_warning_message" 
    android:textColor="@color/password_dialogUI_warning_color" 
    android:id="@+id/dialogUI_warning_text" 
    android:textSize="12sp" 
    android:visibility="invisible" 
    android:fontFamily="sans-serif" 
    android:paddingStart="4dp" 
    android:paddingEnd="4dp" 
    android:layout_marginStart="8dp"/> 

<Space 
    android:layout_width="match_parent" 
    android:layout_height="8dp" /> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingBottom="8dp"> 

<Button 
    android:text="@string/password_ok_button" 
    android:textColor="@drawable/layout_disable_text_color" 
    android:minWidth="64dp" 
    android:layout_width="wrap_content" 
    android:layout_height="36dp" 
    android:id="@+id/password_dialogUI_ok_button" 
    android:layout_alignParentEnd="true" 
    style="?android:attr/borderlessButtonStyle" 
    android:background="@drawable/layout_password_button_background" 
    android:layout_marginEnd="8dp"/> 

<Button 
    android:text="@string/password_cancel_button" 
    android:textColor="@drawable/layout_disable_text_color" 
    android:minWidth="64dp" 
    android:layout_width="wrap_content" 
    android:layout_height="36dp" 
    android:id="@+id/password_dialogUI_cancel_button" 
    style="?android:attr/borderlessButtonStyle" 
    android:layout_toStartOf="@+id/password_dialogUI_ok_button" 
    android:background="@drawable/layout_password_button_background" 
    android:layout_marginEnd="8dp"/> 

+0

Kannst du mir zeigen "layout_password.xml" Datei? –

+0

Bitte schauen Sie sich die geänderte Frage an – newszer

Antwort

1
  1. In Aktivität, versuchen Sie verwenden fragment.show() zu verwenden, statt Ihre eigene Show zu nennen ().

    PasswordDialog fragment = PasswordDialog(); 
    fragment.show(getFragmentManager(), "TAG_HERE"); 
    


2. android hinzufügen: minWidth und android: minHeight auf Ihre xml.

<LinearLayout android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:minWidth="1000dp" 
android:minHeight="1000dp"> 

Siehe unten: Full Screen DialogFragment in Android


Hinzugefügt:

  1. Ihre DialogFragment Zum Ändern der Größe, können Sie Werte in onResume gesetzt.

    public void onResume() 
    { 
        super.onResume(); 
        Window window = getDialog().getWindow(); 
    
        // You can define popup_width and popup_height 
        int width = getResources().getDimensionPixelSize(R.dimen.popup_width); 
        int height = getResources().getDimensionPixelSize(R.dimen.popup_height); 
    
        window.setLayout(width, height); 
        window.setGravity(Gravity.CENTER); // Optional 
    } 
    

Siehe unten:
How to set DialogFragment's width and height?
https://stackoverflow.com/a/17916441/850347

+0

Danke, ich versuche, Show-Funktion direkt aufzurufen, es funktioniert, Sie sparen meinen Tag, aber ich habe die Dialogbreite als die 70% der Bildschirmbreite nicht funktioniert, wissen Sie, wie Sie es einstellen ? – newszer

+0

Ich habe über Resize FragmentDialog hinzugefügt. Wenn es Ihnen gefällt, können Sie diese Antwort als "akzeptiert" auswählen. –

Verwandte Themen