2016-10-05 3 views
0

に画像ビューの後ろに影を追加するアンドロイドのデフォルトの影と例の画像です:
enter image description hereはここアンドロイド の画像ビューの後ろに影を追加アンドロイド

と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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.home.fmat.MainActivity"> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/on" 
    android:src="@drawable/Google_Duo" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"/> 

</RelativeLayout> 
+0

xmlのレイアウトを表示 – user1506104

+0

ヌルの背景を設定することができますが、 'android:background ="?アンドロイド:attr/selectableItemBackground "'がより正しいと思います –

+0

その質問は茶色の背景色について質問していません – paulcab

答えて

0

デフォルトのImageButtonの背景です。 ImageView

<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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.home.fmat.MainActivity"> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/on" 
    android:background="@drawable/bg_button" 
    android:src="@drawable/Google_Duo" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"/> 

</RelativeLayout> 

またはあなたは、消える効果をクリックしてカスタムの背景とのImageButtonの背景を設定したくない場合は、statelistdrawable使用することにより、たとえば、あなたのドロウアブルで、たとえば、あなたがbg_button.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@android:color/red" android:state_pressed="true"/> 
    <item android:drawable="@android:color/red" android:state_hovered="true"/> 
    <item android:drawable="@android:color/transparent"/>  
</selector> 
を定義することができると 変更 ImageButton
+0

statelistdrawableを使用する方法 – paulcab

+0

私の答えを更新する、私はそれがあなたを助けることを願って – hakim

+0

bg_button.xmlを作成するときに "要素セレクタを宣言する必要があります"というエラーが表示される – paulcab

関連する問題