AppCompat で用意されているテーマ
- Theme.AppCompat
- Theme.AppCompat.Light
- Theme.AppCompat.Light.DarkActionBar
次のように自分でダイアログのテーマを作ることはできます。
android:windowBackground に指定する画像(下記だと @drawable/dialog_full_holo_light)を platform から取ってこないといけないですが。
- <resources xmlns:android="http://schemas.android.com/apk/res/android">
- <style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
- <style name="AppTheme" parent="AppBaseTheme">
- <item name="android:windowBackground">@drawable/bg</item>
- </style>
- <style name="AppTheme.Dialog">
- <item name="android:windowFrame">@null</item>
- <item name="android:windowBackground">@drawable/dialog_full_holo_light</item>
- <item name="android:windowIsFloating">true</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
- <item name="android:windowActionBar">false</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowActionModeOverlay">true</item>
- <item name="android:windowCloseOnTouchOutside">false</item>
- </style>
- </resources>
- <item name="android:windowActionBar">true</item>
- <item name="android:windowNoTitle">false</item>
- java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout
なので、View で実装した DialogFragment を用意することになるのかな。
- public class SimpleDialogFragment extends DialogFragment {
- public static SimpleDialogFragment getInstance(String title, String message) {
- Bundle args = new Bundle();
- args.putString("title", title);
- args.putString("message", message);
- SimpleDialogFragment f = new SimpleDialogFragment();
- f.setArguments(args);
- return f;
- }
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- Bundle args = getArguments();
- String title = args.getString("title");
- String message = args.getString("message");
- View view = LayoutInflater.from(getActivity())
- .inflate(R.layout.fragment_dialog, null);
- TextView tv;
- // title
- tv = (TextView) view.findViewById(R.id.title);
- tv.setText(title);
- // message
- tv = (TextView) view.findViewById(R.id.message);
- tv.setText(message);
- Dialog dialog = new Dialog(getActivity(), R.style.AppTheme_Dialog);
- dialog.setContentView(view);
- return dialog;
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/title"
- style="?attr/actionBarStyle"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:gravity="center_vertical"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <TextView
- android:id="@+id/message"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dip"
- android:autoLink="web|email"
- android:linksClickable="true" />
- </ScrollView>
- </LinearLayout>
# ちなみに ActionBar Sherlock は Dialog サポートしてます
Actionbar Sherlockも4.3.0でダイアログのテーマを廃止したようです。。見当違いのことをいっていたらすみません、、
返信削除https://github.com/JakeWharton/ActionBarSherlock/commit/601bde214b56b8fad0b4fc5aaed5af0b531b6135