2012-06-20 3 views
15

Ich verwende ein DialogFragment. Ich möchte, dass die positiven und negativen Schaltflächen über der Tastatur bleiben, wenn der Benutzer mit einem Bearbeitungstext wie in den Beispielbildern unten auf einem Bildschirm in der Google Mail-Tablet-Anwendung interagiert.Wie Sie DialogFragment positive/negative Tasten über der Soft-Tastatur halten

without soft keyboard

With soft keyboard - buttons remain above keyboard as dialog resizes and content scrolls

In meinem Versuch, die hier nicht funktioniert ist mein Dialog Fragment onCreateDialog Methode

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 

    LayoutInflater factory = LayoutInflater.from(getActivity()); 
    final View textEntryView = factory.inflate(R.layout.my_layout, null); 

    return new AlertDialog.Builder(getActivity())     
      .setTitle(getString(R.string.paypal)) 
      .setView(textEntryView) 
      .setPositiveButton(R.string.dialog_ok, 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) {       

        } 
       } 
      ) 
      .setNegativeButton(R.string.dialog_cancel, 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

        } 
       } 
      ) 
      .create(); 
} 

und hier ist die R.layout.my_layout

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true"> 


    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> 
     <ImageView android:id="@+id/paypal_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dip" 
       android:layout_marginBottom="15dip" 

      /> 
     <EditText 
      android:id="@+id/edit_paypal_email" 
       style="@style/GeneralEditText" 
       android:hint="@string/contact_info_text_email" 
       android:inputType="textEmailAddress" 
       /> 

      <View 
      android:id="@id/horizontal_line" 
      style="@style/HorizontalLine" 
      android:layout_marginTop="@dimen/contact_info_line_margin_top" /> 

     <!-- Notes --> 
     <TextView 
      android:text="@string/paypal_info1" 
      style="@style/ContactInfoNotes" 
      android:paddingBottom="5dip" 
      /> 

     <TextView 
      android:text="@string/paypal_info2" 
      style="@style/ContactInfoNotes" 
      android:paddingBottom="5dip" 
      /> 

     <TextView 
      android:text="@string/paypal_info3" 
      style="@style/ContactInfoNotes" 
      android:paddingBottom="5dip" 
      /> 
     <TextView 
      android:text="@string/paypal_info4" 
      style="@style/ContactInfoNotes" 
      android:paddingBottom="5dip" 
      /> 

    </LinearLayout> 
</ScrollView> 

In meiner Implementierung, die so ft Tastatur kommt und deckt die positiven und negativen Knöpfe der Dialoge ab. Was fehlt mir, damit die Tasten über der Tastatur bleiben?

Vielen Dank im Voraus.

Antwort

26

Fügen Sie einfach diese auf Ihrem onViewCreated:

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 
    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
    super.onViewCreated(view, savedInstanceState); 
} 
+0

Danke! Dies funktionierte für mich in einem ähnlichen Szenario; edittext statt buttons. – Karl

+2

Wenn Sie DialogFragment ohne Standardschaltflächen verwenden und das Layout des Dialogfelds scrollbar machen möchten, muss das Layout in ScrollView und 'getDialog() enthalten sein. GetWindow(). SetSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);' sollte innerhalb 'onViewCreated gesetzt werden() ' –

0

Ich glaube, das hat mit den LinearLayout und ScrollView zu tun. Entfernen Sie den fillViewport-Teil aus der ScrollView und zeigen Sie die Bildlaufleiste im LinearLayout an.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:scrollbars="vertical" 
     android:scrollbarAlwaysDrawVerticalTrack="true"> 
     <!-- Stuff --> 

    </LinearLayout> 
</ScrollView> 
+0

Danke, aber die Tasten sind immer noch ausgeblendet. – Dittimon

0

Haben Sie versucht, das folgende Attribut zum activity Tag in Ihrem Manifest hinzufügen?

<activity android:name=".SampleActivity" 
    android:windowSoftInputMode="adjustResize" 
    ... > 
</activity> 
+0

Danke, aber das hat die Tastatur nicht davon abgehalten, die Tasten zu verdecken – Dittimon

3

Ich hatte das gleiche Problem, und ich fand eine Lösung. Der wesentliche Teil der Layout-Datei:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 
<!-- Form items --> 
</ScrollView> 

<!-- Include the layout which contains the buttons --> 
<include layout="@layout/fragment_dialog_button_bar" android:layout_weight="0" /> 

So müssen Sie die Tasten auf layout_weight 0, während der Scroll Gewicht 1 oder größer.

Ich hoffe, das wird helfen.

0

Das hat bei mir funktioniert.

public class Fragment1 extends DialogFragment{ 
    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState){ 
    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
    super.onViewCreated(view, savedInstanceState); 
    } 
} 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:fillViewport="true" 
     android:layout_weight="1" 
     android:layout_height="300dp" > 

     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:inputType="textMultiLine|textAutoCorrect|textCapSentences" 
      /> 
    </ScrollView> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     /> 

</LinearLayout>