大家好,我正在制作一个应用程序,在其中显示带有背景图像的弹出窗口,
我给弹窗设置的背景图片是透明图片 但问题是,当显示弹出窗口时,背景图像显示不正确....
虽然它是一个透明图像,但它在图像的一角显示黑色 strip ..
谁能帮帮我??
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>
最佳答案
Jayesh,试试这个:
popUp.setBackgroundDrawable(new ColorDrawable(
android.graphics.Color.TRANSPARENT));
关于android - 如何显示带有透明背景图像的弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677586/