質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

1回答

695閲覧

ボタンにエフェクト効果をつけたいです

Taka787

総合スコア23

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

1グッド

0クリップ

投稿2020/03/13 07:41

実現したいこと

OKボタンとキャンセルボタンにエフェクト効果をつけたいのですが、対応するXMLファイルがないためか以下のXMLコードでは実現できませんでした。どなたかご教授いただけませんでしょうか?

XML

1android:foreground="?android:selectableItemBackground"

以下は、kotlinコードです

kotlin

1 private fun showConfirmationDialog(pileId: Int) { 2 val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialog) 3 builder.setTitle(Html.fromHtml("<b>" + getString(R.string.pilecheck_confirm_confirmtv) + "</b>")) 4 builder.setMessage(R.string.pilecheck_confirm_confirm_message) 5 6 builder.setPositiveButton(getString(R.string.ok)) { _, _ -> 7 mCheckPileViewModel.setSelectedPileId(pileId) 8 } 9 10 builder.setNegativeButton(getString(R.string.cancel)) { _, _ -> 11 } 12 13 val alertDialog: AlertDialog = builder.create() 14 15 alertDialog.setCancelable(false) 16 17 alertDialog.setOnShowListener { 18 val positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) 19 positiveButton.setTextColor( 20 ContextCompat.getColor( 21 requireContext(), 22 R.color.select_inspection_list_text_color 23 ) 24 ) 25 positiveButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20F) 26 positiveButton.setBackgroundResource(android.R.color.transparent) 27 28 val negativeButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) 29 negativeButton.setTextColor( 30 ContextCompat.getColor( 31 requireContext(), 32 R.color.select_inspection_list_text_color 33 ) 34 ) 35 negativeButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20F) 36 negativeButton.setBackgroundResource(android.R.color.transparent) 37 38 val messageBox = alertDialog.findViewById<TextView>(android.R.id.message) 39 messageBox?.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20F) 40 } 41 alertDialog.show() 42 }
s.k👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quadii.shii

2020/03/13 07:45

AlertDialogのボタンにエフェクトを付けようとしておられると見受けます。 どのようなエフェクトを付けたいのですか?
guest

回答1

0

コメント中のリンクをいただいた通り、Rippleエフェクトを所望と思います。

私もAlertDialogのボタンに適用したことはないですが、Button取得の流れはしっかりされているようですので、

Kotlin

1val positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) 2 positiveButton.setTextColor( 3 ContextCompat.getColor( 4 requireContext(), 5 R.color.select_inspection_list_text_color 6 ) 7 ) 8 positiveButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20F) 9 positiveButton.setBackgroundResource(android.R.color.transparent)

最後の行のpositiveButton.setBackgroundResource(android.R.color.transparent)の代わりに、
リップルエフェクトを仕込んだdrawableリソースのIDをセットしてあげれば動くと思います。

いろいろいじり方があるようなので試してみると良いと思います。
https://qiita.com/pside/items/587dd9f1562d02d2ee2c

投稿2020/03/13 08:01

quadii.shii

総合スコア257

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問