@Override
protected void onCreate(Bundle savedInstanceState) {
String email = getIntent().getStringExtra(AppConstants.REGISTER_EMAIL_INTENT_KEY);
if (email != null && !email.isEmpty())
{
// We have the valid email ID, no need to take it from user, prepare transparent activity just to perform bg tasks required for login
setTheme(R.style.Theme_Transparent);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
else
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dummy);
}
Remember one Important point here: You must call the setTheme() function before super.onCreate(savedInstanceState);. I missed this point and stucked for 2 hours, thinking why my theme is not reflected at run time.
Using Theme.NoDisplay will still work… but only on older Android devices. On Android 6.0 and higher, using Theme.NoDisplay without calling finish() in onCreate() (or, technically, before onResume()) will crash your app. This is why the recommendation is to use Theme.Translucent.NoTitleBar, which does not suffer from this limitation.”
I just did two things, and it made my activity transparent. They are below.
In the manifest file I just added the below code in the activity tag.
And I just set the background of the main layout for that activity as "#80000000". Like
It perfectly works for me.
In my case, i have to set the theme on the runtime in java based on some conditions. So I created one theme in style (similar to other answers):
Then in Java I applied it to my activity:
Remember one Important point here: You must call the
setTheme()
function beforesuper.onCreate(savedInstanceState);
. I missed this point and stucked for 2 hours, thinking why my theme is not reflected at run time.Assign the translucent theme to the activity that you want to make transparent in the Android manifest file of your project:
In the onCreate function, below the setContentView, add this line:
The easiest way that I have found is to set the activity's theme in the AndroidManifest to
android:theme="@android:style/Theme.Holo.Dialog"
.Then in the activity's onCreate method, call
getWindow().setBackgroundDrawable(new ColorDrawable(0));
.There're two ways:
Using
Theme.NoDisplay
will still work… but only on older Android devices. On Android 6.0 and higher, using Theme.NoDisplay without callingfinish()
inonCreate() (or, technically, before onResume())
will crash your app. This is why the recommendation is to useTheme.Translucent.NoTitleBar
, which does not suffer from this limitation.”