android - 如何显示带有透明背景图像的弹出窗口?

标签 android

enter image description here

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

我给弹窗设置的背景图片是透明图片 但问题是,当显示弹出窗口时,背景图像显示不正确....

虽然它是一个透明图像,但它在图像的一角显示黑色 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/

相关文章:

android - React Native - 根据背景颜色更改文本颜色

android - FAB 未使用 RecyclerView 定位在 CoordinatorLayout 内

android - 访问远程 gradle 依赖

java - 如何在运行时知道数据库大小

javascript - Google Identity 工具包验证 IdToken 时出错(客户端 : Android, 后端 : Node. js)

android - 带复选框的 ListView 项目 - 如何删除复选框波纹效果?

android - 我可以在没有 'page=number' 查询的情况下将 Paging3 库用于 API 吗?

android - 如何在 Android 上实现 WebRTC 以实现应用到应用的调用?

android - 如何使内部文件在 Honeycomb 上可读?

android - 录像同时回调onPreviewFrame