完全に透明なダイアログの場合、これを使用できます:
ステップ 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);