Activity with transparent background.

I am creating a loading reuse screen that can be used between actions, in the LoadingActivity application I added a translucent background resource, but I can’t 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

+6
source share
1 answer

Have you tried to customize the theme in action through the manifest file?

 <activity android:name=".LoadingActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> 
+18
source

Source: https://habr.com/ru/post/899984/


All Articles