Saad Bilal
Saad Bilal

Reputation: 1837

How to disable click listener of button if there is overlay

I am using frame layout and linear layout overlay, when click on overlay so button click listener is also invoked, kindly let me know how to handle this.

   <LinearLayout
    android:id="@+id/logLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/transparentBlack"
    android:orientation="vertical" >


   <com.valspals.classes.ButtonStyleM700
            android:id="@+id/logDone"
            android:layout_width="325dp"
            android:layout_height="35dp"
           android:layout_gravity="center"

            android:layout_marginTop="25sp"

            android:background="@drawable/btn_confirm_normal"
            android:text="@string/iamdone"
            android:textColor="@color/White"
            android:textSize="@dimen/normalTextSize" />


    <com.valspals.classes.ButtonStyleM700
            android:id="@+id/woops"
            android:layout_width="325dp"
            android:layout_height="35dp"
           android:layout_gravity="center"

            android:layout_marginTop="15sp"
            android:layout_marginBottom="25dp"
            android:background="@drawable/btn_confirm_normal"
            android:text="@string/woops"
            android:textColor="@color/White"
            android:textSize="@dimen/normalTextSize" />



</LinearLayout>

above this there is frame layout, basically its a parent layout. behind this layout i have two buttons and problem is that they are click able from this linear layout overlay

Upvotes: 1

Views: 1428

Answers (1)

Cruceo
Cruceo

Reputation: 6834

There are several options you could use for this. The easiest would be setting a global variable and checking it when onClick is called.

i.e. you have a boolean overlayShowing = false;

In your event listener, just check for !overlayShowing

However, that will still allow the button's click animation to show. If you want to prevent that as well, you could intercept the touch events on the top layout (your FrameLayout) and prevent them from being passed to the below layouts if the overlay is visible.

e.g. In your overridden FrameLayout:

@Override
public boolean onInterceptTouchEvent(MotionEvent e){
    return overlayShowing;
}

This will intercept the touch event and prevent it from passing it on the chain when the overlay is showing.

If your overlay is only shown by toggling the View's visibility, you could simplify that even further by checking the FrameLayout's visibility in the onInterceptTouchEvent() method. e.g.

@Override
public boolean onInterceptTouchEvent(MotionEvent e){
    return getVisibility() == View.VISIBLE;
}

Upvotes: 1

Related Questions