2011-10-10 88 views
0

我在如何創建自己的自定義對話框中掙扎。如何創建不帶窗口的自定義對話框

我按照這個example

1)我需要的一個功能是禁用「窗口」背景 - 當前當我顯示一個對話框時,就像有一些透明度的黑色背景。我如何在沒有這個「窗口」背景或完全透明的情況下製作它?

2)如何設置對話框的大小?

3)我想添加一個圖像到對話框的背景 - 我如何使它透明?

編輯*

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

我用這種風格對我的對話,並添加使用的FrameLayout的背景下,這樣的:

final CustomDialog dialog = new CustomDialog(context, R.style.Dialog); 
ImageView image = new ImageView(context); 
image.setImageResource(R.drawable.background2); 
image.setAlpha(75); 
image.setVisibility(View.VISIBLE); 

final FrameLayout frameLayout = new FrameLayout(context); 
frameLayout.setPadding(40, 100, 40, 100); 
frameLayout.addView(image, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

View layout = inflater.inflate(R.layout.dialog, null); 
frameLayout.addView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
dialog.setContentView(frameLayout); 
+0

哪裏?我沒有發現任何與透明度相關的東西 – piojo

回答

0
  1. 您應該能夠設置對話框完全透明的:
    Dialog myDialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
  2. 如果您爲對話框自定義佈局,則應該可以設置寬度屬性的高度&。
  3. 將ImageView設置爲背景,然後使用 myImage.setAlpha(127)調整透明度;
+0

沒有工作,或者我做錯了什麼 – piojo

+0

你可以發佈一些你的代碼,我會盡力幫助你。最終, – SBerg413

+0

工作。我編輯我的問題,我做了什麼。 – piojo