I want to create a transparent Activity on top of another activity.
How can I achieve this?
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:
@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.