Android 自定义对话框
程序员文章站
2022-08-02 22:30:45
public class CustomDilaog { private Context context; private Dialog dialog; public CustomDilaog(Context context) { this.context = context; dialog = ne... ......
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(); } }); }
上一篇: 每天喝多少豆浆为宜,适量喝豆浆有什么好处