1、定義style:
<resources>
<style
name="dialog_fullscreen">
<item
name="android:windowFullscreen">true</item>
<item
name="android:windowNoTitle">true</item>
<item
name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
2、定義layout檔案:test_dialog.xml
<LinearLayout
android:id="@+id/ll_dialog"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#000000">
……
</LinearLayout>
3、代碼中設定:
public class TestDialog extends Dialog
{
public TestDialog(Context context)
{
super(context, R.style.dialog_fullscreen);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test_dialog);
// 設定背景透明度
View ll = findViewById(R.id.ll_dialog);
ll.getBackground().setAlpha(120);// 120為透明的比率
}
}
本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/cruel/archive/2011/01/05/6118806.aspx