<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">1、AlertDialog由于是对Dialog的封装,所以,在调用setContentView 的方法时候不可在构造函数内调用。而Dialog的则可以。原因在于</span>
源码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAlert.installContent();// private AlertController mAlert;
}
<strong><span style="color:#330033;background-color: rgb(255, 204, 204);">mAlert.installContent();对应的源码:</span></strong>
public void installContent() {
/* We use a custom title so never request a window title */
mWindow.requestFeature(Window.FEATURE_NO_TITLE);
if (mView == null || !canTextInput(mView)) {
mWindow.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
mWindow.setContentView(mAlertDialogLayout);
setupView();
}
由此可见 mWindow.requestFeature(Window.FEATURE_NO_TITLE); 的调用导致setContentView 不可提前使用。
2、有个奇怪的问题:就是对于输入法Dialog可以自动隐藏输入法,而AlertDialog则不可以,此问题,哪位大侠知道可以留言,感谢!(失之东隅,收之桑榆:如果需要不隐藏输入法的效果,可以使用AlertDialog,反之,可以继承Dialog)
以上的问题记录都是继承AlertDialog或者Dialog的方式使用。而并不是 AlertDialog.Builder.对于此会不会出现同样问题,尚未验证
附上测试源码:见下一章节