0

I'm a bit new to Android, therefore question may sound ridiculous, but:

Is there any way to make a button in form of smthg? There ate tons of apps, where you press on a tree or some house and some action starts. How is that made? Not action, but form. Or there is no way to make button NOT rectangular?

  • 1
    Possible duplicate of [How to create custom button in Android using XML Styles](http://stackoverflow.com/questions/18507351/how-to-create-custom-button-in-android-using-xml-styles) – Morrison Chang Jul 04 '16 at 06:01
  • Button is View like an ImageView or TextView, you might be talking about onClick Listeners see here http://stackoverflow.com/questions/3505841/onclick-listener-in-android – johnrao07 Jul 04 '16 at 06:01
  • 1
    Hi, Welcome to Stackoverflow. Please note that your question is voted for closed by 2 persons so far, Due to the quality of post. Please post questions here once you tried and failed (Only after doing enough research on the same question). Also post the code, stacktrace or images of the problem that you are tackling to resolve. – Viswanath Lekshmanan Jul 04 '16 at 06:07
  • Buttons are Views which are always rectangular but doesn't need to look like they are rectangular. Alternatively look at: http://stackoverflow.com/questions/16670774/clickable-area-of-image – Morrison Chang Jul 04 '16 at 06:19

3 Answers3

3

You are talking about imagebutton.Image button documentation

For example creating a button with tree background.Example:

<ImageButton android:src="@drawable/tree.png"></ImageButton>
Javasamurai
  • 666
  • 7
  • 21
1

Yes you can do that. Considering your trees and house as an image.

    ImageView im;
    im = (ImageView) findViewById(R.id.image_of_tree);
    im.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //perform some action
        }
    });
Nishant Thapliyal
  • 1,540
  • 17
  • 28
0

Off-course When you get inflated your layout and your view(can be any view) is available by id. your button can be an ImageView, ImageButton etc. just find the id for your view and set whatever event you want to listen by this view.