3
我有一個問題,直到還找不到解決方案!我用幾個鍵實現了一個自定義鍵盤。每個鍵都有一個背景圖像。我想改變按鍵本身的背景色顯示在下面的原裝鍵盤:Android自定義鍵盤更改背景顏色鍵按下
我不想有一個預覽,我想改變密鑰本身的背景顏色,當按鍵被按下時。下面是我的文件:
keyboard.xml
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewOffset="10dp"
android:keyPreviewLayout ="@layout/preview"
android:keyTextColor="@color/colorAccent"
android:keyBackground="@drawable/keybackground"
android:background="#881f2023"
/>
keybackground.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_pressed="true"
android:drawable="@drawable/cleandeactivate" />
<item
android:state_checkable="true"
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_checkable="true"
android:state_pressed="true"
android:drawable="@drawable/cleandeactivate" />
<item
android:state_checkable="true"
android:state_checked="true"
android:drawable="@drawable/cleanbuttonnormal" />
<item
android:state_checkable="true"
android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/keybackground" />
</selector>
的背景顏色將變爲我的繪製,但是當我命中關鍵,它不會改變到按下狀態。背景保持不變。你可以幫我嗎?
在這裏我的自定義鍵盤佈局,啓用預覽顯示該按鈕被擊中。
與8的黑色按鈕應該得到黃色。預覽用於調試目的。
感謝亞歷山大的回覆!我理解這個問題,但我在哪裏改變這個?哪些文件首先被檢查?如何將我的特定background.xml文件設置爲第一個背景?我注意到我犯了一個錯字。我糾正了一次。我使用了cleanbuttonnormal的keybackground.xml。現在看起來像我的代碼。 – user3325230
只需嘗試相反的順序! –
謝謝!沒有意識到這個事實。你是對的,只是移動上面的檢查狀態,一切正常!謝謝! – user3325230