Click an image button for tracking in Android

Source: Internet
Author: User

In many cases, we need to customize the image button in android, instead of the system. Today, let's take a look at how to implement this simple requirement.

(1) first, prepare necessary resources. Here, I have prepared three images as follows:




(2) create an android project, create a drawable folder under res, and create a button. xml file under the drawable folder. the specific content of the file is as follows:

 
     
      
  
 
At the same time, copy the three images background.jpg?start_a.png=start_ B .png TO THE drawable-hdpi folder.

(3) Modify activity_main.xml in layout. The modified content is as follows:

 
         
      
      
  
 
Note that you need to set the background attribute of ImageButton to "#0000" so that the effect of the custom image button is not affected.

(4) The main Activity defaults to setContentView (R. layout. activity_main). The MainActivity content is as follows:

import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        getMenuInflater().inflate(R.menu.activity_main, menu);        return true;    }}

Right-click the project and run our android application. The result is as follows:

Source code:

Click an image button for tracking in android


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.