1

I've developed a login page and have created a custom xml layout for a loading screen. Everything in the layout for the loading screen is contained within a RelativeLayout. When the user hits the sign in button, the loading screen gets placed over the top of the current layout indicating that it is loading.

Problem

The problem is, when the loading screen is over the top of the login layout, you can still click through the loading screen on the buttons behind it, thus creating multiple actions that I don't want. Is there a simple way to make the whole RelativeLayout not clickable?

I've tried things such as:

android:clickable="false"
android:focusable="false"

with no success.

Community
  • 1
  • 1
Romes
  • 3,088
  • 5
  • 37
  • 52

2 Answers2

3

you can make the background of the loading screen clickable="true" and assign it no action so that it prevents clicks from passing through it

chris-tulip
  • 1,840
  • 1
  • 15
  • 22
1

I've had situations such as this and I find the easiest solution is to make your loading dialog take up all of the screen space. The main container for the dialog should be transparent with the actual loading dialog centered inside of that. Here is an example of what I did.

My loading dialog layout:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/stericson.busybox.donate"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#AA000000"
    android:id="@+id/main">

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/roundedborder_black_translucent"
        android:layout_centerInParent="true"
        android:padding="10dip">

        <ProgressBar 
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerVertical="true"
            android:id="@+id/progress"
            android:layout_marginRight="10dp"/>

        <stericson.busybox.donate.custom.FontableTextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/progress"
            android:textColor="#ffffff"
            android:id="@+id/header"/>

        </RelativeLayout>          
    </RelativeLayout>

The drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="2dp" android:color="#909090" /> 
    <solid android:color="#CC000000" /> 
    <padding android:left="7dp" android:top="7dp" 
        android:right="7dp" android:bottom="7dp" /> 
    <corners android:radius="6dp" /> 
</shape> 

The code to show it:

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View layout = inflater.inflate(R.layout.popupwindow_spinner, null); 
        App.getInstance().setPopupView(layout);

        popupWindow = new PopupWindow(layout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

        context.findViewById(R.id.main).post(new Runnable() {
   public void run() {
       try
       {
           popupWindow.showAtLocation(context.findViewById(R.id.main), Gravity.CENTER, 0, 250);
       }
       catch (Exception e)
       {
           //do nothing
       }
   }
    });

        TextView textView = (TextView) layout.findViewById(R.id.header);
        textView.setText(context.getString(stringId));

And the id main is simply the parent container of my main view:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/stericson.busybox.donate"
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#303030" >

I believe you need to have your application use the translucent theme in order to use transparent backgrounds like I did here:

<activity android:theme="@android:style/Theme.Translucent"> 

Since the loading screens fills the entire screen it does not allow clicks to go through to what is under it.

Stericson
  • 415
  • 2
  • 5