0

Android アプリケーションのメイン アクティビティの上に表示されるダイアログ スタイルのアクティビティがあります。背景を半透明にする方法を教えてください。透明ではありませんが、半透明です。たとえば、70% 不透明です。このテーマをアクティビティに適用してみました:

    <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android: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>  

これにはいくつかのバリエーションがありますが、それでもダイアログ アクティビティは 100% 不透明に見えます。また、アクティビティ自体 (およびアクティビティに表示される要素) のレイアウト xml は、「#70000000」の背景を指定します。

4

1 に答える 1

3

完全に透明なダイアログの場合、これを使用できます:

ステップ 1> 「res」の下の「values」フォルダーに colors.xml ファイルを作成し、次の行を追加します。

<drawable name="transparent">#00000000</drawable>

ステップ 2> 「res」の下の「values」フォルダーに、styles.xml ファイルを作成し、次の行を作成します…</p>

<style name="Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">
@android:style/Animation.Translucent
</item>
<item name="android:windowBackground">@drawable/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>

(タグと属性は一目瞭然だと思います…)

ステップ 3> 実は、それだけです……………………</p>

これをダイアログに追加しましょう…..

ステップ 4> 次の行でクラスを作成します……</p>

public class DialogBox extends Dialog {

    public DialogBox(Context context, int theme) {
        super(context, theme);
        setContentView(R.layout.dialog);
        okButton = (Button) findViewById(R.id.dialog_OkButton);
        setListeners();
    }
}

(ダイアログのレイアウトを必ず作成してください)

ステップ 5> 次に、次のようにアクティビティ クラスを作成します。

public class T_Temp extends Activity {

    private DialogBox dialog;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        dialog = new DialogBox(this, R.style.Transparent);
        dialog.show();
    }
}

または、これを使用してダイアログを魅力的にし、ぼかし効果を追加できます....

これをチェックしてください: 透明度は約 30% 近くあります...

 dialog = new AlertDialog.Builder(WordCube.this)  
    .setTitle(WordCube.this.getResources().getString(R.string.app_name))  
    .setMessage(s)  
    .setIcon(R.drawable.logo)  
    .setPositiveButton(R.string.btn_close, null)  
    .show();  

以下は、ぼかしを追加して背景の減光を削除するために必要なコードを示しています (背景が明るいとぼかしがきれいに見えると思います)。

view plaincopy to clipboardprint?
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();  
lp.dimAmount=0.0f;  
dialog.getWindow().setAttributes(lp);  
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);  
于 2013-03-22T05:40:46.167 に答える