-2

My application must show a couple of images at the bottom of each screen for a few seconds each time the user navigates between fragments. I have implemented it as a custom toast, and I activate it with each navigation. It looks good, but the user cannot click anything while the toast is active. As soon as the toast goes away, they can click and everything works fine. Is there any way to enable user interaction on the views underneath a toast while the toast is visible?

Update:

Here's the code that displays my toast:

    LayoutInflater inflater = mainActivity.getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast, null, false);

    Toast toast = new Toast(mainActivity.getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();

Here's the layout for the toast:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:gravity="bottom"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true">

<ImageView
    android:id="@+id/imageViewStatsLogo"
    android:layout_width="80dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    android:layout_height="30dp"
    android:scaleType="centerInside"
    android:src="@drawable/stats_logo" />

<ImageView
    android:id="@+id/imageViewAPLogo"
    android:layout_width="35dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_height="30dp"
    android:scaleType="centerInside"
    android:src="@drawable/ap_logo" />

</RelativeLayout>

I just tested with a non-custom toast, and I can interact with everything just fine. It must be something with my custom toast. I thought the configuration I have for the relative layout would cause it to only occupy the bottom of the screen. It is acting as though the toast is filling the whole screen.

async8192
  • 199
  • 2
  • 8

2 Answers2

0

I have tested it. I am sure that user interaction on the views underneath a toast can be done correctly. All you have to do is making the toast translucently so that user can see the views.

zhenghuiyan
  • 324
  • 4
  • 10
  • I can see all the controls under the toast. I just can't click anything. Is there an attribute I need to set in the layout, or a setting on the toast to provide "translucency"? – async8192 May 25 '14 at 06:38
  • I think something wrong in the other part.can you show the whole activity file? – zhenghuiyan May 25 '14 at 08:35
0

After much trial and error, I discovered that a linear layout must be used around the relative layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="horizontal" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="70dp"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:src="@drawable/stats_logo" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/ap_logo" />
</RelativeLayout>

</LinearLayout>

and the gravity needs to be set on the toast to make it be on the bottom:

    LayoutInflater inflater = mainActivity.getLayoutInflater();
    View layout = inflater.inflate(R.layout.stats_ap_toast, null, false);

    Toast toast = new Toast(mainActivity.getApplicationContext());
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();

Now user interaction with the view beneath the toast is working.

async8192
  • 199
  • 2
  • 8