I'm trying to use a custom layout file for an alert dialog on android (support library version 26.1.0)
I've tried using the following:
<style name="MyTheme"...>
<item name="alertDialogTheme">@style/MyTheme.AlertDialog</item>
</styles>
<style name="MyTheme.AlertDialog" parent="Base.AlertDialog.AppCompat">
<item name="android:layout">@layout/custom_abc_alert_dialog_material</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="buttonBarNegativeButtonStyle">@style/MyTheme.Button.Negative</item>
<item name="buttonBarNeutralButtonStyle">@style/MyTheme.Button.Neutral</item>
<item name="buttonBarPositiveButtonStyle">@style/MyTheme.Button.Positive</item>
</style>
I can tell it's picking up the actual theme, as the button styles are updated. However, it's not picking up the custom layout file. I see this code in AlertController in the support library:
mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0);
which translates back to the source:
<declare-styleable name="AlertDialog">
<attr name="android:layout"/>
...
</declare-styleable>
I also see this in the support library values.xml file:
<style name="Base.AlertDialog.AppCompat" parent="android:Widget">
<item name="android:layout">@layout/abc_alert_dialog_material</item>
I suspect my usage of android:layout
is not being picked up due to the above styleable declaration. I just have no idea how to overcome that and properly specify the layout.
I realize I could use a custom view and use setView on the dialog, but that's intrusive when all I want to do is re-arrange a few things on the layout (which can't be controlled with theme attributes sadly enough)
I also realize I could just replace abc_alert_dialog_material.xml entirely, but then it's replaced for all themes, not just the one I'm working with.
Does anyone have any idea what I might be missing here to properly use my custom layout file? ?