警报对话框的自定义布局文件

时间:2017-12-13 17:02:19

标签: android android-support-library

我试图在Android上使用自定义布局文件 警告对话框(支持库版本26.1.0)

我尝试过使用以下内容:

<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>

随着按钮样式的更新,我可以告诉它正在拾取实际主题。但是,它没有拿起自定义布局文件。我在支持库中的 AlertController 中看到了这段代码:

    mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0);

转换回来源:

<declare-styleable name="AlertDialog">
  <attr name="android:layout"/>
  ...
</declare-styleable>

我也在支持库 values.xml 文件中看到了这一点:

<style name="Base.AlertDialog.AppCompat" parent="android:Widget">
    <item name="android:layout">@layout/abc_alert_dialog_material</item>

我怀疑由于上面的样式声明,我没有使用android:layout。我根本不知道如何克服这个问题并正确指定布局。

我意识到我可以使用自定义视图并在对话框中使用setView,但是当我想要做的就是重新安排布局上的一些事情时(这是无法控制的)可悲的主题属性)

我也意识到我可以完全替换 abc_alert_dialog_material.xml ,但是它已经替换了所有主题,而不仅仅是我正在使用的主题。

有没有人知道我在这里可能缺少什么来正确使用我的自定义布局文件? ?

0 个答案:

没有答案