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.
setTheme(android.R.style.Theme_Dialog);
you can use
setTheme(..)
before callingsetContentView(...)
andsuper.oncreate()
and it should work fineWould like to give a work around for this problem.
Problem : How to use the same activity as both dialog and full screen based.
Solution :
@android:style/Theme.Dialog
.Java
file, check for anintent
extra that definesdialog
mode.Theme
toandroid.R.style.Theme
. This is the defaulttheme
which is applied if you do not define any theme.Code :
Alternate Solution:
A more complex solution is to use
AlertDialog
as below:ListAdapter
class extended fromArrayAdapter
.return
1
ingetCount
functionIn the
getView
function,inflate
thelayout
of theactivity
you need and do any customization before returning theview
.This is definitely a second choice option by if you are not doing too much processing in the
activity
class
this could be an option.Only reason to consider this solution could be that the logic to show it in a
dialog
is isolated to the places where it is used as a dialog.Both the options worked for me but for obvious reasons I am taking the first option. :-)