Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:22:45+00:00 2026-05-22T15:22:45+00:00

So I have an Activity (say TestActivity ) which needs to act as a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:22:46+00:00Added an answer on May 22, 2026 at 3:22 pm

    Would like to give a work around for this problem.

    Problem : How to use the same activity as both dialog and full screen based.

    Solution :

    1. Define your activity in your AndroidManifest.xml with the theme @android:style/Theme.Dialog
    2. In your respective .Java file, check for an intent extra that defines dialog mode.
    3. If it does not exist, set the Theme to android.R.style.Theme. This is the default theme which is applied if you do not define any theme.

    Code :

    boolean fDialogMode = getIntent().hasExtra("dialog_mode");
    
    if( ! fDialogMode ) {
        super.setTheme(android.R.style.Theme);
    }
    

    Alternate Solution:

    A more complex solution is to use AlertDialog as below:

    1. Define a ListAdapter class extended from ArrayAdapter.
    2. return 1 in getCount function

      @Override
      public int getCount() { return 1; }
      
    3. In the getView function, inflate the layout of the activity you need and do any customization before returning the view.

      @Override
      public View getView( int position, View view, ViewGroup group ) {
          View v = view;
          if( v == null ) {
              v = getSystemService(Context.LAYOUT_INFLATER_SERVICE).inflate( <layout res id>, null );
          }
      
      ... Do any customization here    ....
      
            return v;
      }
      

    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. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Activity A which calls B, at which point let's say the user
I have a couple of tables which are used to log user activity for
I have an Activity ActivityA say. From ActivityA I start ActivityB using an Intent,
Lets say I have a Service S and Activity A. S downloads data for
So, lets say in my main activity, i have an array declared like this,
I have an activity that has a TabHost containing a set of TabSpecs each
i have created a workflow activity that do give the item creater of a
I have a need to do auditing all database activity regardless of whether it
I have a web-based application that notifies users of activity on the site via
Have just started using Visual Studio Professional's built-in unit testing features, which as I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.