简体   繁体   中英

How to Create Login Screen with an overlay in android

I have been trying to create an overlay for a login screen in android without any luck.

My scenario is as follows

  1. I implemented the login in a class that extends async task.
  2. I want to show a transparent full screen overlay with a loading gif image.
  3. When the async task completes close overlay and take the user to the main Activity.

I am new to android programming any help will be well appreciated.

You can try this, it works for me:

Create this class:

public class LoadingDialog extends Dialog {

    public LoadingDialog(final Context ctx) {

        super(ctx);
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        this.setContentView(R.layout.dialog_loading);
    }
}

This is the layout file (dialog_loading.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true" />
</LinearLayout>

And in your activity:

LoadingDialog dialog = new LoadingDialog(yourActivity.this);
dialog.show();

I guess you could use a Fragment logic for the transaction time and change it later to your main activity.

Not sure what do you mean by "transparent overlay".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM