2011-10-10 96 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