我在一個活動佈局定義了以下按鈕:按鈕state_pressed =「真」從來沒有觸發,爲什麼?
<Button
android:id="@+id/button_Collect"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="16dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/selector_CollectButton" />
有了它,我有這樣的選擇,應用於按鈕:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<!-- PRESSED STATE (Opacity change to 75) -->
<!-- ==================================== -->
<layer-list>
<!-- Shape for the outer circle -->
<item opacity="75">
<shape android:shape="oval">
<solid android:color="#FFBDC3C7" />
</shape>
</item>
<!-- Shape for the circle -->
<item android:top="18dp" android:left="18dp" android:right="18dp" android:bottom="18dp">
<shape android:shape="oval">
<!--<solid android:color="#FF3498DB" />-->
<solid android:color="#FF22DD44" />
</shape>
</item>
</layer-list>
</item>
<item>
<!-- NORMAL STATE -->
<!-- ============ -->
<layer-list>
<!-- Shape for the outer circle -->
<item>
<shape android:shape="oval">
<solid android:color="#FFBDC3C7" />
</shape>
</item>
<!-- Shape for the circle -->
<item android:top="18dp" android:left="18dp" android:right="18dp" android:bottom="18dp">
<shape android:shape="oval">
<solid android:color="#FF3498DB" />
</shape>
</item>
</layer-list>
</item>
</selector>
爲什麼是它的按下狀態從未跳跳虎每當我在我的應用程序中觸摸按鈕?
我也嘗試將我的「狀態」分成單獨的xml可繪製文件,但問題仍然存在。
至於事件,我在我的活動如下:
Button btnCollect = FindViewById<Button>(Resource.Id.button_Collect);
btnCollect.Touch += btnCollect_Touch;
這是C#代碼,因爲我與Xamarin合作。此代碼執行時沒有問題,所以我知道觸摸事件正在執行。
UPDATE:
我想通一些東西,它只能如果我刪除上面的事件處理程序:
我有以下代碼:
private void btnCollect_Touch(object sender, View.TouchEventArgs e)
{
if (e.Event.Action == MotionEventActions.Up)
ScoreManager.Instance.CalculatePoints();
}
如果我不去添加一個處理程序,該選擇器正常工作,任何人都知道爲什麼?
你的代碼在哪裏設置OnClickListener並處理點擊? –
我更新了我的OP。 – Maximus
對不起。不知道C#API。不過,我會建議拿出選擇器,看看它是否有效。分而治之! –