为完全透明的对话框u可以使用这样的:
步骤1>下创建 'RES' 中的 '值' 文件夹中的文件colors.xml和添加以下行..
<drawable name="transparent">#00000000</drawable>
步骤2>中创建下“RES”的“值”文件夹和如下的styles.xml文件...
<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>
(I猜标记和属性是自解释的...。)
步骤3>其实这就是它........................
让我们将它添加到一个对话框... ..
步骤4>创建具有以下行的一类......
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();
}
}
或U可以使用它来进行对话的吸引力增加模糊效果....
只是检查了这一点:有近ABT 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);