AlertDialogにスタイルが適用されなくて無邪気におかしいなとか思った話
android接頭辞のつく属性はサポートライブラリのスタイルには使わない。
Created at

402 Words
⚠️

android:接頭辞のつく属性はサポートライブラリのスタイルには使わない。

以上。

発生した問題

  1. AlertDialogを使うときに、うっかりandroidx.appcompat.app.AlertDialogandroid.app.AlertDialogを混在させていた。

  2. そのどちらでも共通のスタイルを使用していた。

  3. アプリで使用するダイアログで下部ボタン(Positive, Negative, Neutral)の色がちゃんとスタイル適用されるものとされないものがあった。

原因

注: サポート ライブラリの属性名は、android: 接頭辞を使用しません。これは Android フレームワークの属性にのみ使用します。

スタイルとテーマ | Android Developers

はい切腹しますありがとうございました。

修正

  1. すべてのAlertDialogインポート部分をandroidx.appcompat.app.AlertDialogに統一。

  2. ボタンスタイルを次のように指定。

<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarNeutralButtonStyle">@style/NeutralButtonStyle</item>

See Also