首页 > 移动平台 > 详细

Android 自定义对话框

时间:2019-11-05 14:55:09      阅读:121      评论:0      收藏:0      [点我收藏+]
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();
            }
        });
    }

技术分享图片

Android 自定义对话框

原文:https://www.cnblogs.com/zhangxuechao/p/11798173.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!