开发者

how to create a Custom dialog with no window

I struggling with how to create my own custom dialog.

I follow this example.

1)one feature I need is to disable the "window" background - currently when I show a dialog there's like a black background with some transparency. how do I make it without this "window" background or completely transparent?

2) How do I set the size of the dialog?

3) I want to add an image to the background of the dialog - how do I make it transparent ?

edit*

<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>

I used this style for my Dialog and add the background using frameLayout, like this:

 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.WR开发者_如何学PythonAP_CONTENT, LayoutParams.WRAP_CONTENT));
 dialog.setContentView(frameLayout);


  1. You should be able to set the dialog completely transparent with:
    Dialog myDialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
  2. If you customize a layout for your dialog, you should be able to set the height & width attributes.
  3. Set an ImageView as your background and then adjust the transparency with myImage.setAlpha(127);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜