Android用の小さなゲームを作成しています。現在、メニュー画面のUIを作成中です。
私は木のテーマをやっているので、ハイスコアなどを表示するためのカスタムダイアログも使いたいので、テーマに従います。
良いガイドをいくつか見つけましたが、ダイアログの背景に非常に奇妙な問題があります。ダイアログはほとんど透明です。
私がやったこと: - dialog_theme.xml を作成しました:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Dialog" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
- 必要な要素 (タイトルとコンテンツの TextView、閉じるボタン) を含む custom_dialog.xml を作成しました。
- Dialog を拡張する CustomDialog クラスを作成し、必要なコンテンツとタイトルでこれらのカスタム ダイアログをかなり簡単に作成できるようにしました
- アクティビティで CustomDialog を使用してダイアログを作成する
(この blog.androgames.net/10/custom-android-dialog/ で使用したメイン ガイド)
問題は、透明な背景が常に透明であるとは限らないことです (アクティビティ UI が背景に表示されます)。このメニューには 4 つのカスタム ボタンがあります。問題は、ダイアログを透明に表示してUI全体を背景に表示するのではなく、ボタンの画像の1つが引き伸ばされてダイアログの背景全体を埋めることです。この 1 つのボタンに標準の背景を使用するだけの場合、ダイアログの背景は透明になり、バックグラウンドでアクティビティ UI が表示されます。
説明が下手だったかもしれないので、私が言いたいことの写真を示します: - 問題を引き起こすボタンのコード:
<Button
android:id="@+id/id_about_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/id_achievements_button"
android:layout_marginTop="15dp"
android:background="@drawable/selector_about" />
この結果が得られます: (申し訳ありませんが、投稿で直接写真を使用することはまだできません) http://dl.dropbox.com/u/2980431/wrong.png
ボタンのコードを次のように変更します。
<Button
android:id="@+id/id_about_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/id_achievements_button"
android:layout_marginTop="15dp"/>
この結果が得られます: http://dl.dropbox.com/u/2980431/correct.png
なぜこれが起こっているのか、そしてそれを修正するための解決策について誰かが考えてくれることを願っています-正直に言うと、私は完全に迷っています。