如何制作一个像广告一样的弹出图像? [安卓] [英] How to make a pop up image like an advertisement? [Android]

查看:107
本文介绍了如何制作一个像广告一样的弹出图像? [安卓]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了很多弹出图像,如下例所示,我制作了一个弹出图像,但是左上角没有关闭按钮,你们是否知道如何制作弹出图像图像的左上角有关闭按钮,就像Android中的以下示例一样?

I've encountered a lot of pop up images like the example below, i've made a pop up image but there is no close button at the top left corner, do u guys have any idea how to make a pop up image with close button at the top left cornel like the example below in Android?

推荐答案

您需要使用自定义布局制作自己的对话框

You need to make your own Dialog with your custom layout

Dialog dialog;

private void showDialog() {
    // custom dialog
    dialog = new Dialog(this);
    dialog.setContentView(R.layout.custom_dialog);

    // set the custom dialog components - text, image and button
    ImageButton close = (ImageButton) dialog.findViewById(R.id.btnClose);
    Button buy = (Button) dialog.findViewById(R.id.btnBuy);

    // Close Button
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            //TODO Close button action
        }
    });

    // Buy Button
    buy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            //TODO Buy button action
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    dialog.show();
}

custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:background="@android:color/white"
        android:orientation="vertical">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/images" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp">

            <Button
                android:id="@+id/btnBuy"
                android:layout_width="80dp"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:background="@android:color/holo_green_light"
                android:text="BUY"
                android:textColor="@android:color/white" />

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/btnBuy"
                android:text="Thank You (Domestic Album Version)"
                android:textColor="@android:color/black"
                android:textStyle="bold" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtTitle"
                android:text="Still Not Gettin' Any, 2004" />

        </RelativeLayout>
    </LinearLayout>

    <ImageButton
        android:id="@+id/btnClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@android:color/black"
        android:src="@android:drawable/ic_menu_close_clear_cancel" />


</RelativeLayout>

结果是:

这篇关于如何制作一个像广告一样的弹出图像? [安卓]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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