Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity with a transparent background

I'm creating a reusable Loading screen to use between Activities, on the LoadingActivity I added a semi transparent background resource, but I'm unable to see the old Activity.

public class LoadingActivity extends Activity {
    public static int REQUEST_LOADING_SCREEN = 40;

    @Override
    protected void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);

        FrameLayout mainLayout = new FrameLayout(this);

        mainLayout.setBackgroundResource(R.drawable.background_translucent);

        LinearLayout layout = new LinearLayout(this);
        layout.setGravity(Gravity.CENTER);

        LayoutParams params = LayoutParamsFactory.newMatchFrameLP();
        params.gravity = Gravity.CENTER;
        mainLayout.addView(layout, params);

        ProgressBar bar = new ProgressBar(this);
        bar.setIndeterminate(true);
        layout.addView(bar, LayoutParamsFactory.newWrapLinearLP());

        TextView text = new TextView(this);
        text.setText("Loading...");
        layout.addView(text, LayoutParamsFactory.newWrapLinearLP());

        setContentView(mainLayout);
    }

    public static void openFor(Activity activity) {
        Intent intent = new Intent(activity, LoadingActivity.class);
        activity.startActivityForResult(intent, REQUEST_LOADING_SCREEN);
    }

    public static void closeFrom(Activity activity) {
        activity.finishActivity(REQUEST_LOADING_SCREEN);
    }
}

EDIT:

Even with:

mainLayout.setBackgroundColor(Color.TRANSPARENT);
layout.setBackgroundColor(Color.TRANSPARENT);

The background is still black

like image 758
Marcos Vasconcelos Avatar asked Oct 24 '11 18:10

Marcos Vasconcelos


People also ask

What is a transparent activity?

In Android, we can create a transparent activity that will not be visible but your application will be running. The best part of this transparent activity is that you can create a transparent activity by just changing the resource file and we need not write the java or kotlin code for the same.

How do you make a transparent activity in flutter?

Just copy the string. replace transparent. toString() with "transparent" .


1 Answers

Have you tried setting the theme on the activity via the manifest file?

<activity android:name=".LoadingActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
like image 180
Joe Avatar answered Nov 07 '22 21:11

Joe