Search code examples
androidandroid-layoutandroid-button

How to set button have image and shadow?


To make shadow, make shadow xml file and use like android:background="@drawable/shadow". But put image is android:background="@drawable/image too.

how to set button shadow and image in one button?

I'm sorry I'm not fluent in English.


Solution

  • 1. use ImageButton

    try this you can use ImageButton :- Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states.

     <ImageButton
      android:id="@+id/btnMain"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"
      android:contentDescription="@string/btnMain_description"
      android:elevation="10dp"
      android:background="@android:drawable/dialog_holo_light_fram‌​e"
      android:scaleType="centerInside"
      android:src="@drawable/IMage"
     />
    

    2. user CardVirew or you can try this add your button inside card view like this

    compile this dependencies

    compile 'com.android.support:cardview-v7:25.3.1'
    

    layout like this

        <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="10dp">
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/disha"
            android:text="@string/app_name" />
    </android.support.v7.widget.CardView>
    

    ask me in case of any query