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.