700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android dialog控件初始化 自定义AlertDialog控件的使用(AndroidStudio)

android dialog控件初始化 自定义AlertDialog控件的使用(AndroidStudio)

时间:2021-01-17 04:22:21

相关推荐

android dialog控件初始化 自定义AlertDialog控件的使用(AndroidStudio)

AlertDialog 第一种:可随意自定义控件

第一步:自定义弹出的页面 ,新建一个XML页面 如下图 不需要Activity

第二步:在主页面设置一个按钮弹出上图页面 (下面是主要代码 调用自动以XML文件显示在AlertDialog中)

final AlertDialog dialog = new AlertDialog.Builder(container.getContext()).create();//实例化一个AlertDialog

dialog.show(); //把AlertDialog初始化

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);//设置将输入法显示出来

dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); //指定输入法显示在该窗口 设置输入法可见性

final Window window = dialog.getWindow(); //实例化一个窗口

window.setContentView(R.layout.activity_alert_error_document);//调用自定义的XML放到AlertDialog中展示

TextView txtDocumentNumber = (TextView) window.findViewById(R.id.txtDocumentNumber);//获

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。