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.
Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file.
How to programatically resize and show them? Use a android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling. All of these attributes can be set in code on each ImageButton at runtime.
So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not.
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_frame"
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
create button_selector.xml in res/drawable :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
And in your xml layout:
<ImageButton
android:src="@mipmap/ic_launcher"
android:background="@drawable/shadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="10dp"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With