So I have an Activity
(say TestActivity
) which needs to act as a normal unthemed Activity
as well as a Theme.Dialog
at other place. I am trying to reuse same TestActivity
for both the tasks.
All I am looking for setting the theme dynamically.
The code is simple:
Here is my activity's onCreate
that works with a black background
public void onCreate(Bundle icicle) {
if (Utility.isDialog == true)
setTheme(android.R.style.Theme_Dialog);
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
.....
and here is the Manifest Entry
<activity android:name=".TestActivity"/>
And in the meantime I found a post that says it can't be done here is the post http://code.google.com/p/android/issues/detail?id=4394 .But there is a strong feeling that it can be done.
All suggestions are welcome.
Like several others, calls to setTheme in onCreate (before or after my call to super.onCreate) did not work. However, by overriding setTheme, I was able to specify a theme other than that stated in Manifest.xml. Specifically, the following worked without issue:
I found the above in the discussion at: https://code.google.com/p/android/issues/detail?id=4394
I know that I am late but I would like to post a solution here:
Check the full source code here. This is the code I used when changing theme...
use
setTheme
before callingsuper.onCreate(savedInstance)
This may not be applicable in your situation, but you can use the theme:
and it will display your activity as a dialog when the screen is large, and as a regular activity when the screen is small. This is covered in the Android documentation on Dialogs and also contains information on programming a Dialog which can also sun as a full screen fragment.
Default theme library call:
In my case I was using AppCompat Theme, so make sure that on your id you refer the proper library (i.e.):
super.setTheme(android.support.v7.appcompat.R.style.Theme_AppCompat_NoActionBar);
Call
Activity.setTheme()
inonCreate()
before you callsetContentView()
.