Androidアプリをつくっています。
ボタンをタップしたら、ボタンの背景色が変わるようにしたいです。
一応調べてやってはみましたが、デバッグすると、アプリが落ちてしまいます。
(背景色に関する記述を消すと通常通りに動きます)
やり方が悪いのか、そもそも出来ないのか、ご教授頂きたいです。
###参考にしたサイト
http://y-anz-m.blogspot.com/2010/01/android-button.html
https://inon29.hateblo.jp/entry/2014/01/13/184153
###ちなみに
タップしたらText Viewの文字色を変えるようにすることはできるのですが...
XML
1Main.axml 2 3<?xml version="1.0" encoding="utf-8"?> 4<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 5 android:orientation="vertical" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent"> 8 <TextView 9 android:text="Text" 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:id="@+id/textView2" 13 android:textColor="@drawable/text" 14 android:clickable="true" /> 15</LinearLayout>
XML
1drawable配下にtext.xmlを作成 2 3<?xml version="1.0" encoding="UTF-8" ?> 4<selector xmlns:android="http://schemas.android.com/apk/res/android"> 5<item android:state_focused="true" android:state_pressed="false" android:color="#5ea9ff" /> 6 <item android:state_focused="true" android:state_pressed="true" android:color="#5e3fff" /> 7 <item android:state_focused="false" android:state_pressed="true" android:color="#5e3f4b" /> 8 <item android:color="#ee7c43" /> 9</selector>
これでタップしたらTextの文字色が変わります
###これと同じような要領で、、、
タップしたらボタンの背景色を変えたいのですが、出来ないのでしょうか?
※ちなみにJava等で書けば出来ることは分かっているのですが、そんなとこまでJavaで書きたくないので...
環境
環境はVisual Studio Community for Macを使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/30 13:20
退会済みユーザー
2018/07/30 13:36
2018/07/31 12:48
退会済みユーザー
2018/07/31 13:12
2018/08/01 13:14