ImageButton
私の単純な目標は、さまざまなボタンの状態の背景を変更することです。だから、私が持っているのは
mylayout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity"
android:orientation="vertical"
android:id="@+id/idBackground">
...
<ImageButton
android:id="@+id/btnCapture"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/ic_photo_selector"
android:src="@drawable/ic_photo"
android:padding="25dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
...
</RelativeLayout>
ic_photo_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval" >
<gradient
android:centerColor="#3311ffed"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#8011ffed"
android:gradientRadius="150"
android:startColor="#2711ffed"
android:type="radial" />
<stroke
android:width="2dp"
android:color="#3300DDFF" />
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />
</shape>
</item>
<item android:drawable="@drawable/capture_button_bg"/>
</selector>
capture_button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:centerColor="#1111ffed"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#5E11ffed"
android:gradientRadius="150"
android:startColor="#0511ffed"
android:type="radial" />
<stroke
android:width="2dp"
android:color="#1100DDFF" />
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />
</shape>
ic_photo.png (透過画像ですが、こちらのサイトは背景が白なので黒レイヤーに載せました)
したがって、ご覧のとおり、両方の状態 (押された状態と既定の状態) の視覚的な違いは透明になっているはずです。しかし、実際のデバイスとしての設計モードは別の結果を示しました
デフォルト状態 押された状態
![]()
![]()
私の心は本当にブロックされています。デフォルトのボタンと押されたボタンの色が違うのはなぜですか? 予想通り、違いは透明度モードだけです。
何か案は?それとも私のコードスニペットに何か問題があるのでしょうか?