在源码中有如下AlertDialog
protected AlertDialog(Context context) {
this(context, com.android.internal.R.style.Theme_Dialog_Alert);
}
其中Theme_Dialog_Alert在哪里呢?
我们到res下面找到value里面的themes.xml里面的Theme_Dialog_Alert,但是这样是找不到的,需要把下划线"_"改成".",这样就ok了
<!-- Default theme for alert dialog windows, which is used by the
{@link android.app.AlertDialog} class. This is basically a dialog
but sets the background to empty so it can do two-tone backgrounds. -->
<style name="Theme.Dialog.Alert">
<item name="windowBackground">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="windowTitleStyle">@android:style/DialogWindowTitle</item>
<item name="windowIsFloating">true</item>
<item name="windowContentOverlay">@null</item>
<item name="android:gravity">center</item>
</style>
在AlertController中
TypedArray a = mContext.obtainStyledAttributes(
null, com.android.internal.R.styleable.AlertDialog, com.android.internal.R.attr.alertDialogStyle, 0);
针对R.attr.alertDialogStyle
pateo@pateo-B86N53X:/work/project/f0400s/frameworks/base/core/res$ grep -r "alertDialogStyle" ./
./res/values/attrs.xml: <attr name="alertDialogStyle" format="reference" />
./res/values/attrs.xml: <attr name="dlsalertDialogStyle" format="reference" />
./res/values/public.xml: <public type="attr" name="alertDialogStyle" id="0x0101005d" />
./res/values/themes.xml: <item name="alertDialogStyle">@android:style/AlertDialog</item>
./res/values/themes.xml: <item name="dlsalertDialogStyle">@android:style/DlsAlertDialog</item>
pateo@pateo-B86N53X:/work/project/f0400s/frameworks/base/core/res$
pateo@pateo-B86N53X:/work/project/f0400s/frameworks/base/core/res$
找到styles.xml文件里面的AlertDialog
<style name="AlertDialog">
<item name="fullDark">@android:drawable/popup_full_dark</item>
<item name="topDark">@android:drawable/popup_top_dark</item>
<item name="centerDark">@android:drawable/popup_center_dark</item>
<item name="bottomDark">@android:drawable/popup_bottom_dark</item>
<item name="fullBright">@android:drawable/popup_full_bright</item>
<item name="topBright">@android:drawable/popup_top_bright</item>
<item name="centerBright">@android:drawable/popup_center_bright</item>
<item name="bottomBright">@android:drawable/popup_bottom_bright</item>
<item name="bottomMedium">@android:drawable/popup_bottom_medium</item>
<item name="centerMedium">@android:drawable/popup_center_medium</item>
</style>