15

私はDialogFragmentを使用しています。Gmail タブレット アプリケーションの画面から下の例の写真のように、ユーザーが編集テキストを操作するときに、正と負のボタンがキーボードの上に残るようにします。

ソフトキーボードなし

ソフト キーボードを使用 - ダイアログのサイズが変更され、コンテンツがスクロールしても、ボタンはキーボードの上に残ります

うまくいかない私の試みでは、ここに私のDialog Fragments onCreateDialogメソッドがあります

@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();
}

ここに 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>

私の実装では、ソフト キーボードが表示され、ダイアログの正と負のボタンがカバーされます。ボタンをキーボードの上に残すには何が欠けていますか?

前もって感謝します。

4

5 に答える 5

28

これをonViewCreatedに追加するだけです:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    super.onViewCreated(view, savedInstanceState);
}
于 2012-08-14T17:49:23.253 に答える
4

私は同じ問題を抱えていましたが、解決策を見つけました。レイアウト ファイルの重要な部分:

<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" />

したがって、ボタンの layout_weight を 0 に設定する必要がありますが、スクロールビューの重みは 1 以上です。

これが役立つことを願っています。

于 2012-08-18T18:12:42.040 に答える
0

activityマニフェストのタグに次の属性を追加してみましたか?

<activity android:name=".SampleActivity"
    android:windowSoftInputMode="adjustResize" 
    ... >
</activity>
于 2012-06-20T00:21:20.867 に答える
0

これが私のために働いたものです。

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>
于 2013-02-01T19:58:54.673 に答える
0

これは と に関係していると思いLinearLayoutますScrollView。ScrollView から fillViewport 部分を削除し、LinearLayout にスクロールバーを表示します。

<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>
于 2012-06-20T00:15:57.697 に答える