I want a button that it has a background image and when I click that button,the button's background or color change (and we go to another activity.) Tell me how can I make this.
Asked
Active
Viewed 46 times
1 Answers
0
Create an xml
file and save it in one of the drawable
folders in your project,let bg.xml
,set this one as the background of your Button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/button_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/button_notpressed" />
</selector>
where button_pressed
and button_notpressed
are the images which you want to show on transition of the clicks and normal view of button
In your activity's xml
file,set the background of the button
as bg.xml
<Button
android:id="@+id/btn"
android:layout_width="150dp"
android:layout_height="60dp"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="450dp"
android:background="@drawable/bg" <--! set it like this-->
android:text="Submit"
android:textColor="#FFFFFF" />

nobalG
- 4,544
- 3
- 34
- 72
-
Can you explain me selector(what do that do) – Paul Oct 16 '14 at 13:25
-
[Please see this](http://developer.android.com/reference/java/nio/channels/Selector.html) – nobalG Oct 16 '14 at 13:27
-
Excuse me but how or where can I download pdf that has every thing about android programming and ofcourse articles in developer.android. – Paul Oct 16 '14 at 13:37
-
I want a pdf or book that teach android regularly. I mean how did you learn android programming – Paul Oct 16 '14 at 13:49
-
Try developing some application, on the way you will come across issues and concepts, google them, if issues, then post them on stackoverflow ...anyways I will search for you for some pdf...mail me on my email id from my profile...I will send you one – nobalG Oct 16 '14 at 13:54
-
Could you simply explain me oncreate bundle and override and other things in first part of java files. Another question is that what is the difference between editable and string. Simply please – Paul Oct 16 '14 at 17:17
-
[onCreate Description](http://stackoverflow.com/questions/19538976/what-is-a-oncreate-method-in-android) – nobalG Oct 17 '14 at 04:35