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);
- You should be able to set the dialog completely transparent with:
Dialog myDialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar); - If you customize a layout for your dialog, you should be able to set the height & width attributes.
- Set an ImageView as your background and then adjust the transparency with myImage.setAlpha(127);
精彩评论