想实现画面弹出的对话框为自定义式样,第一时间会习惯用AlertDialog
AlertDialog customDialog = new AlertDialog.Builder(MainActivity.this).create();
LayoutInflater inflater = LayoutInflater.from(this);
View contentView = inflater.inflate(R.layout.custom_dialog_content, null);
customDialog.setView(contentView);
可由于AlertDialog带有系统自定义好的式样,会在对话框四周出现黑色背景,设置自己view的背景色也无效,没什么简单的方法直接进行式样设定:
参考的 stackoverflow的提问,其实可以利用Dialog来实现:
Dialog customDialog = new Dialog(this);
customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
customDialog.setContentView(R.layout.custom_dialog_content);
效果如下:
不过左边会出现一条很细的竖线(红框标识),原因待查,所用手机为HTC G12 , version 2.3.
本文讨论了如何在Android应用中实现自定义样式对话框,并解决在使用默认AlertDialog时遇到的问题。通过使用Dialog替代,成功实现了所需样式并解决了显示边框的问题,特别针对HTC G12机型进行了验证。
457

被折叠的 条评论
为什么被折叠?



