如何显示带有透明背景图像的弹出窗口? [英] how to display a popup windows with transparent background image?

查看:114
本文介绍了如何显示带有透明背景图像的弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在制作一个应用程序,其中显示带有背景图片的弹出窗口,

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

有人可以帮我吗?

PopupDemoActivity.java

PopupDemoActivity.java

package com.demo.popupwindow.;

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

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,试试这个:

Jayesh, try this :

popUp.setBackgroundDrawable(new ColorDrawable(
            android.graphics.Color.TRANSPARENT));

这篇关于如何显示带有透明背景图像的弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆