Reputation: 443
I have written a Custom Dialog, which works perfectly fine.
public class GalleryAlertDialog extends Dialog {}
In a class I call the class with the
dialog.show();
I want to achieve this look:
I need the button over the dialog,like this.
However, this is what I get:
Here's the layout xml's part where I declare the layout and the button inside it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_buttonContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dip"
android:gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="@+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_button_popupclose"
android:contentDescription="TODO"
android:tag="btn_close" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_pagerContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ll_buttonContainer"
android:layout_marginTop="80dip"
android:background="@color/white" />
<ToggleButton
android:id="@+id/tbFavorite"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_gravity="bottom|right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dip"
android:background="@drawable/selector_check"
android:checked="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOff=""
android:textOn="" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ff212121"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/llContactFullName"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/white"
android:gravity="left|center_vertical"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="@color/seperator" />
<TextView
android:id="@+id/txtContactFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/txtCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/txtPosition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
.....
I tried giving the ll_buttonContainer a transparent background programatically too.
llButtonContainer.setBackgroundColor(mContext.getResources().getColor(
R.color.transparent_tr));
llButtonContainer.setBackgroundColor(Color.argb(0, 0, 0, 0));
I even tried
android:background="null"
Nothing works. The layout is still visible, it gets any color (red, yellow, white etc.) other than transparent. Is this how it works, will I not be able to give it transparent background due to how Dialog works?
Thanks for any help.
Upvotes: 2
Views: 5575
Reputation: 381
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:background="#00000000"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
<ImageView
android:id="@+id/ad_view_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="40dp"
android:src="@android:drawable/ic_delete" />
</RelativeLayout>
</RelativeLayout>
in dialog
final Dialog dialog = new Dialog(context);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.ad_view);
dialog.setCancelable(false);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
ImageView closeBtn = ((ImageView) dialog.findViewById(R.id.closeButton));
ImageView addView=((ImageView) dialog.findViewById(R.id.ad_view_image));
addView.setImageBitmap(loadedImage);
closeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
addView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(marketlink.startsWith("http")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketlink));
mContext.startActivity(browserIntent);
dialog.dismiss();
}
}
});
}
Upvotes: 0
Reputation: 443
Ok I found the answer myself.
I found this line on StackOverFlow, tried it and it worked. Writing this line,
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
just before
alertDialog.show();
Hope this helps some one and you won't suffer as much as I do. It's pretty simple, but very annoying if you miss it.
Upvotes: 8
Reputation: 4762
Use this Style into yout res/values/style
making WindowTranparent
<style name="Theme.Transparent" parent="android:Theme">#03afee
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Apply this to your Dialog...
Upvotes: 3