Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:28:19+00:00 2026-06-16T03:28:19+00:00

How can i make a custom shaped clickable view or button in Android? When

  • 0

How can i make a custom shaped clickable view or button in Android?

When I click , I want to avoid touching on an empty area .

enter image description here

please help. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:28:20+00:00Added an answer on June 16, 2026 at 3:28 am

    Interesting question. I tried some solutions and this is what I found that has the same result of what you are trying to achieve. The solution below resolves 2 problems:

    1. Custom shape as you presented it
    2. The top right side of the button shouldn’t be clickable

    So this is the solution in 3 steps:

    Step 1

    Create two shapes.

    • First simple rectangle shape for the button: shape_button_beer.xml

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android" >
      
          <gradient
              android:angle="90"
              android:endColor="#C5D9F4"
              android:startColor="#DCE5FD" />
      
          <corners
              android:bottomLeftRadius="5dp"
              android:bottomRightRadius="5dp"
              android:topLeftRadius="5dp" >
          </corners>
      
      </shape>
      
    • Second shape is used as mask for the top right side of the button: shape_button_beer_mask.xml. It is simple circle with black solid color.

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="oval" >
      
          <solid android:color="#000000" />
      
      </shape>
      

    Step 2

    In your main layout add the button by next approach:

    • RelativeLayout is the container of this custom button
    • First LinearLayout is the blue button with beer icon and text inside
    • Second ImageView is the mask above the blue button. And here comes dirty trick:
      1. Margins are negative to set the mask in the right place
      2. We define id to be able override on click (see step 3)
      3. android:soundEffectsEnabled="false" – such that user will not feel that he pressed on something.

    The XML:

        <!-- Custom Button -->
        <RelativeLayout
            android:layout_width="120dp"
            android:layout_height="80dp" >
    
            <LinearLayout
                android:id="@+id/custom_buttom"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="@drawable/shape_button_beer" >
    
                <!-- Beer icon and all other stuff -->
    
                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="15dp"
                    android:src="@drawable/beer_icon" />
            </LinearLayout>
    
            <ImageView
                android:id="@+id/do_nothing"
                android:layout_width="120dp"
                android:layout_height="100dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="-50dp"
                android:layout_marginTop="-50dp"
                android:background="@drawable/shape_button_beer_mask"
                android:soundEffectsEnabled="false" >
            </ImageView>
        </RelativeLayout>
        <!-- End Custom Button -->
    

    Step 3

    In your main activity you define on click events for both: button and the mask as follow:

    LinearLayout customButton = (LinearLayout) findViewById(R.id.custom_buttom);
    customButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View arg0)
        {
            Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show();
        }
    });
    
    // Mask on click will do nothing
    ImageView doNothing = (ImageView) findViewById(R.id.do_nothing);
    doNothing.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View arg0)
        {
            // DO NOTHING
        }
    });
    

    That’s it. I know that is not a perfect solution but in your described use case it could help.
    I have tested it on my mobile and this is how it looks when you click on the blue area and nothing will happen on other areas:

    • enter image description here

    Hope it helped somehow 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can make custom Exception Handling on objective C... Any useful tutorial please guide
how can i make my custom class serializable and savable into IsolatedStorageSettings as value
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
1) Custom exceptions can help make your intentions clear. How can this be? The
You can see my project here - http://www.inluxphoto.com/custom/jsgallery/index.php I am attempting to make the
I'm developing a WebApp for Android, so I've added a custom button like this:
Can I make a div with a custom shape? I mean, I have a
I can make my program write a .dat file with an array of Node
How can make a link within a facebox window that redirects it to another
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.