Android向けの開発を開始しています。ある種のモーダル アラート (iOS の UIAlertView など) を作成したくありませんでした。うまく機能するActivityの使用を検討しました。私がそれをするのに少し時間がかかりました。しかし後で、DialogFragment を使用してより良い解決策を見つけました。アクティビティをダイアログ フラグメントに変更し、フラグメントに関して必要なすべての部分を変更しました。それは正常に動作します。私のフラグメントの ListView がスクロールしないことを除いて! 問題は何ですか?
注: アクティビティ ソリューションでは既に機能していました。スクロールビューはありません。
XML は次のとおりです。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/modal_list_outter_frame_margin_vertical"
android:layout_marginLeft="@dimen/modal_list_outter_frame_margin_horizontal"
android:layout_marginRight="@dimen/modal_list_outter_frame_margin_horizontal"
android:layout_marginTop="@dimen/modal_list_outter_frame_margin_vertical"
android:background="@drawable/modal_list_outter_frame"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/modal_list_padding_bottom" >
<TextView
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/modal_list_title_horizontal_margin"
android:layout_marginRight="@dimen/modal_list_title_horizontal_margin"
android:layout_marginTop="@dimen/modal_list_title_top_margin"
android:gravity="center"
android:maxLines="@integer/modal_list_title_number_of_lines"
android:shadowColor="@color/modal_list_text_shadow_color"
android:shadowDx="0"
android:shadowDy="@integer/modal_list_title_shadow_offset_y"
android:shadowRadius="@integer/modal_list_title_shadow_radius"
android:text="@string/modal_list_title_small"
android:textColor="@color/modal_list_text_color"
android:textSize="@dimen/modal_list_title_font_size"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/modal_list_inner_frame_margin_bottom"
android:layout_marginLeft="@dimen/modal_list_inner_frame_margin_horizontal"
android:layout_marginRight="@dimen/modal_list_inner_frame_margin_horizontal"
android:layout_marginTop="@dimen/modal_list_inner_frame_margin_top"
android:background="@drawable/modal_list_inner_frame"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/modal_list_padding_bottom" >
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/modal_list_list_view_margin_horizontal"
android:layout_marginRight="@dimen/modal_list_list_view_margin_horizontal"
android:layout_marginTop="@dimen/modal_list_list_view_margin_top"
android:divider="@null"
android:dividerHeight="0dp"
android:listSelector="@color/modal_list_selector_color_selected"
>
</ListView>
</LinearLayout>
</LinearLayout>
更新:本当に奇妙なものを見つけました! まるで破片が透けてる!フラグメント内の何かをタップすると、その下のボタンをタップしているように見えます! フラグメントを表示するために使用しているコードは次のとおりです。
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.addToBackStack("SingleSelectionCustomRowModalList");
modalList = ASModalList.newInstance(modalListStateForCustomRow) ;
modalList.show(ft, "SingleSelectionCustomRowModalList");
更新 2: DialogFragment がモーダルではないことが問題のようです。私はこのスタイルを使用しています:
int style = DialogFragment.STYLE_NO_TITLE | DialogFragment.STYLE_NO_FRAME;
setStyle(style, R.style.ASModaListDialogStyle);
使用するテーマは次のとおりです。
<style name="ASModaListDialogStyle" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/modal_list_background_view</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:gravity">center</item>
</style>
このテーマを使用して、ダイアログの背景を淡色表示にしています。