Hello guys , i am making a application in which I display pop up-windows with background image,
the background image i set to the popup window is transparent image but the problem is that when the popup window is displayed the background image is not displayed properly....
although it is a transparent image it displays the black strip around the corner of image..
can anybody help me out ??
PopupDemoActivity.java
package com.demo.popupwindow.;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
public class PopupDemoActivity extends Activity {
Button searchMenu, viewOrder;
PopupWindow popUp;
LayoutParams params;
FrameLayout layout;
// LinearLayout layout;
boolean click = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popdemodemo);
searchMenu = (Button) findViewById(R.id.menu);
viewOrder = (Button) findViewById(R.id.order);
popUp = new PopupWindow(this);
// layout = new LinearLayout(this);
layout = new FrameLayout(this);
viewOrder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (click) {
popUp.showAtLocation(layout, Gravity.TOP | Gravity.RIGHT,
0, 0);
popUp.update(30, 75, 500, 400);
click = false;
} else {
popUp.dismiss();
click = true;
}
}
});
// popUp.setContentView(layout);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
layout.setBackgroundResource(R.drawable.order_back);
// layout.setBackgroundColor(Color.TRANSPARENT);
popUp.setContentView(layout);
}
}
popupdemo.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white_color"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/header_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/menu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="Search Menu"
android:textColor="@color/white_color"
android:textSize="25sp"
android:textStyle="bold" />
<Button
android:id="@+id/order"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:text="View Order"
android:textColor="@color/white_color"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
As the name suggests, background-color: transparent means you can see through the background of the element, i.e. its background color would appear to be identical to the background color seen on its parent element.
Display pop-up windows while running in the background : this one means to allow the app to draw over the system ui while the app is running in the background like services and broadcast.
Jayesh, try this :
popUp.setBackgroundDrawable(new ColorDrawable(
android.graphics.Color.TRANSPARENT));
set
popUp.setBackgroundDrawable(null);
It should do the work. what you are getting in background is some sort of background content of popup Window
In your XML you are defining the background of your popup as
android:background="@color/white_color"
Try applying background image here rather than on run time.
android:background="@drawable/order_back"
OR
move the popup layout changing code above (before popUp.showAtLocation(layout, Gravity.TOP | Gravity.RIGHT,0, 0);
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With