Android Button onClick Event Example : Getting started with Android
                Today let us see an example for the Android button onclick. When any user clicks on button onClick event of Android Button is executed checkout the following code.
| 
                             
                                1
                               
                              
                                2
                               
                              
                                3
                               
                              
                                4
                               
                             | 
                          
                             
                                Button android:text="@+id/Button01"
                              
 
                              
                                android:id="@+id/Button01"
                               
                              
                                android:layout_width="wrap_content"
                               
                              
                                android:layout_height="wrap_content" />
                               
                             | 
                        
Onclick Action:- Edit your Java code like this
| 
                             
                                1
                               
                              
                                2
                               
                              
                                3
                               
                              
                                4
                               
                              
                                5
                               
                              
                                6
                               
                              
                                7
                               
                              
                                8
                               
                              
                                9
                               
                              
                                10
                               
                              
                                11
                               
                              
                                12
                               
                              
                                13
                               
                             | 
                          
                             
                                public class TechnoCrunchButton extends Activity {
                               
                              
                                Private Button butexample;
                               
                              
                                @Override
                               
                              
                                protected void onCreate(Bundle savedInstanceState) {
                               
                              
                                setContentView(R.layout.main);
                               
                              
                                // Declaring Button
                               
                              
                                butexample = (Button)this.findViewById(R.id.Button01);
                               
                              
                                butexample.setOnClickListener(new OnClickListener() {
                               
                              
                                @Override
                               
                              
                                public void onClick(View v) { // onClick Method
                               
                              
                                // Your Onclick Action Here
                               
                              
                                }});
                               
                              
                                }}
                               
                             | 
                        
By using android:background=”@android:color/transparent” the button background will become transparent. You need to include this code into the Layout XML file.
| 
                             
                                1
                               
                              
                                2
                               
                              
                                3
                               
                              
                                4
                               
                              
                                5
                               
                             | 
                          
                             
                                Button android:text="@+id/Button01"
                              
 
                              
                                android:id="@+id/Button01"
                               
                              
                                android:layout_width="wrap_content"
                               
                              
                                android:layout_height="wrap_content"
                               
                              
                                android:background="@android:color/transparent" />
                               
                             | 
                        
0
                      
0