Search code examples
androidbroadcastreceiveralways-on-top

Touch issue on always on top


I've created a transparent activity with some UI while to show on incoming call. It's working fine but the transparent activity doesn't allow to use the call accept and reject buttons. (Touch is blocked for that System UI). How to overcome this.

CustomDialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="250dp"
    android:layout_height="280dp"
    android:background="@drawable/popup_shape"
    android:padding="5dp"
    android:layout_gravity="center">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/popup_title"
            android:textAllCaps="true"
            android:textColor="@color/white"
            android:textAlignment="center"
            android:layout_marginTop="20dp"
            android:textSize="16dp"
            android:textStyle="bold"/>
        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/mithra"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/popup_description"
            android:textColor="@color/white"
            android:paddingHorizontal="20dp"
            android:textAlignment="center"
            android:textSize="14dp"
            android:layout_marginTop="20dp"/>
        <Button
            android:id="@+id/skipBtn"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/skip_button_shape"
            android:text="Skip"
            android:textColor="@color/white"
            android:textSize="16dp" />
    </LinearLayout>
</LinearLayout>

Solution

  • I solved this by adding the following flag to the transparent activity

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL)