由做Android应用到做Android手机也有些时间了
后仔细想来
相信大家
一种是在Activity里调用showDialog(int)
一种是自己直接用AlertDialog
我把话先说在前头
还有几个
接下来
首先
总的来说
为什么这么说呢
publicfinalvoid showDialog(int id) {
showDialog(id
}
publicfinalboolean showDialog(int id
if (mManagedDialogs == null) {
mManagedDialogs = new SparseArray<ManagedDialog>();
}
ManagedDialog md = mManagedDialogs
if (md == null) {
md = new ManagedDialog();
<span style=
if (md
returnfalse;
}
mManagedDialogs
}
md
<span style=
md
returntrue;
}
private Dialog createDialog(Integer dialogId
<span style=
if (dialog == null) {
returnnull;
}
<span style=
return dialog;
} 这里面可以很明显的看出来
我们也可以看到
这里一直没发现
protectedvoid onCreate(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater
if (mProgressStyle == STYLE_HORIZONTAL) {
/* Use a separate handler to update the text views as they
* must be updated on the same thread that created them
*/
mViewUpdateHandler = new Handler() {
@Override
publicvoid handleMessage(Message msg) {
super
/* Update the number and percent */
int progress = mProgress
int max = mProgress
double percent = (double) progress / (double) max;
String format = mProgressNumberFormat;
mProgressNumber
SpannableString tmp = new SpannableString(mProgressPercentFormat
tmp
mProgressPercent
}
};
View view = inflater
mProgress = (ProgressBar) view
mProgressNumber = (TextView) view
mProgressNumberFormat =
mProgressPercent = (TextView) view
mProgressPercentFormat = NumberFormat
mProgressPercentFormat
<span style=
} else {
View view = inflater
mProgress = (ProgressBar) view
mMessageView = (TextView) view
<span style=
}
setIndeterminate(mIndeterminate);
onProgressChanged();
super
public Builder setView(View view) {
P
P
returnthis;
} 可以看到ProgresDialog只是
protectedvoid onCreate(Bundle savedInstanceState) {
super
mAlert
}
进入AlertController
publicvoid installContent() {
/* We use a custom title so never request a window title */
mWindow
if (mView == null || !canTextInput(mView)) {
mWindow
WindowManager
}
mWindow
setupView();
}
privatevoid setupView() {
LinearLayout contentPanel = (LinearLayout) mWindow
setupContent(contentPanel);
boolean hasButtons = setupButtons();
LinearLayout topPanel = (LinearLayout) mWindow
TypedArray a = mContext
null
boolean hasTitle = setupTitle(topPanel);
View buttonPanel = mWindow
if (!hasButtons) {
buttonPanel
}
FrameLayout customPanel = null;
if (mView != null) {
customPanel = (FrameLayout) mWindow
FrameLayout custom = (FrameLayout) mWindow
custom
if (mViewSpacingSpecified) {
custom
mViewSpacingBottom);
}
if (mListView != null) {
((LinearLayout
}
} else {
mWindow
}
/* Only display the divider if we have a title and a
* custom view or a message
*/
if (hasTitle && ((mMessage != null) || (mView != null))) {
View divider = mWindow
divider
看到了吗?我们前面的mView只是整个Dialog的一部分而已
接下来
AlertDialog
builder
builder
builder
@Override
publicvoid onClick(DialogInterface dialog
dialog
Main
}
});
builder
@Override
publicvoid onClick(DialogInterface dialog
dialog
}
});
builder
public AlertDialog create() {
final AlertDialog dialog = new AlertDialog(P
P
dialog
dialog
if (P
dialog
}
return dialog;
}
看到没有
那我不知道你们没有同样的疑问
呵呵
builder
publicvoid show() {
if (mShowing) {
if (mDecor != null) {
mDecor
}
return;
}
if (!mCreated) {
dispatchOnCreate(null);
}
onStart();
mDecor = mWindow
WindowManager
if ((l
& WindowManager
WindowManager
pyFrom(l);
nl
WindowManager
l = nl;
}
try {
mWindowManager
mShowing = true;
sendShowMessage();
} finally {
}
}
第二种方法的流程是这样的
show()
总算简要的分析完了
提个问题