当前位置: 萬仟网 > IT编程>移动开发>Android > Android 自定义对话框

Android 自定义对话框

2019年11月05日 15:40  | 萬仟网IT编程  | 我要评论
public class customdilaog {

    private context context;
    private dialog dialog;

    public customdilaog(context context) {

        this.context = context;
        dialog = new dialog(context);
    }

    public void show() {

        view view = layoutinflater.from(context).inflate(r.layout.custom, null);
        dialog.setcontentview(view);
        dialog.settitle("自定义对话框");
        imageview imageview = (imageview) view.findviewbyid(r.id.image);
        imageview.setimageresource(r.drawable.a1);
        dialog.show();
    }
}
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="10dp" >

    <imageview
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginright="10dp" />

    <textview
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="自定义对话框内容"
        android:textcolor="#000000" />

</linearlayout>
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);

        button = (button) findviewbyid(r.id.button);
        button.setonclicklistener(new onclicklistener() {

            @override
            public void onclick(view v) {
                // todo auto-generated method stub
                customdilaog dilaog = new customdilaog(mainactivity.this);
                dilaog.show();
            }
        });
    }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

◎已有 0 人评论

Copyright © 2019  萬仟网 保留所有权利. 粤ICP备17035492号-1
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com