1

スタイルに透明なウィンドウの背景が設定されたカスタム ダイアログを作成しています。バックグラウンドと同じ button_selector で設定されたダイアログの背後にあるアクティビティに別のボタンがあり、それは正常に動作するので、問題はスタイル、より具体的には windowBackground 属性にあることがわかります。

カスタム ダイアログの透明なウィンドウの背景を取得する方法を知っている人はいますか?

@drawable/lightblue1 と @drawable/button_selector に設定されたボタンの背景でどのように見えるかの写真が含まれています。

これは私のスタイルのxmlです

<resources>
   <style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
     <item name="android:windowBackground">@color/transparent</item>
     <item name="android:windowIsFloating">false</item>
     <item name="android:windowNoTitle">true</item>
  </style>
</resources>

行を削除すると<item name="android:windowBackground">@color/transparent</item>、ボタン セレクターは正しく機能しますが、ダイアログはシステムの既定のダイアログ コンテナーの背景内に配置されます。

これは私のボタン宣言xmlです。@drawable/button_selector を実際の png ファイルの 1 つに変更すると正しく表示されますが、セレクターを使用するとボタンの背景が透明に設定されます。

  <Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/button_selector"
  android:layout_marginBottom="15dp"
  android:textSize="35sp"
  android:text="@string/btnText1">
  </Button>

Javaからダイアログを作成する方法は次のとおりです。

 Dialog dialog = new Dialog(TimeClock.this, R.style.CustomDialogTheme);
 dialog.setContentView(R.layout.tag);
 dialog.show();

これがbutton_selector.xmlです

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/darkblue1" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/darkblue1" /> <!-- focused -->
     <item android:drawable="@drawable/lightblue1" /> <!-- default -->
 </selector>

編集:ダイアログの外観をより適切に制御できるように、ダイアログを半透明のアクティビティで「偽造」しました。

ボタンをpngファイルに設定して セレクターから設定したボタンで

4

1 に答える 1

4

何がうまくいかないのか正確にはわかりませんが、既存の半透明テーマに基づいて CustomDialogTheme を定義する価値があるでしょうか? 例えば

<resources>
   <style name="CustomDialogTheme" parent="@android:style/Theme.Translucent.NoTitleBar">

次のような追加のスタイル項目のいくつかを設定する必要がある場合もあります (この質問から取得):

<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsFloating">true</item>

Android がこれらの設定のいずれかを使用して、ボタン セレクターを機能させているのではないかと思っていました。

于 2011-10-30T04:16:24.677 に答える