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

  • SEARCH
  • Home
  • 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 8653333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:31:02+00:00 2026-06-12T14:31:02+00:00

I have some difficulties with setting up a theme switcher programmatically. I would like

  • 0

I have some difficulties with setting up a “theme switcher” programmatically.
I would like to switch themes from app (between White (Theme.Light.NoTitleBar) and Dark (Theme.Black.NoTitleBar)) and what I do is:
I set a SharedPreference:

final String PREFS_NAME = "MyPrefsFile";
    final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    final SharedPreferences.Editor editor = settings.edit();

and than I have a two buttons to switch themes (second one is almost identical)

Button ThemeWhite = (Button) findViewById(R.id.ThemeWhite);
    ThemeWhite.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            editor.putBoolean("Theme", false);
              editor.commit();
              System.exit(2);
        }
    });

and in begging of each activity I check SharedPreference

boolean theme = settings.getBoolean("Theme", false);
    if(theme){
        this.setTheme(R.style.Theme_NoBarBlack);
    } else{
        this.setTheme(R.style.Theme_NoBar);
    }

    setContentView(R.layout.aplikacja);

I define themes in file styles.xml in folder values:

<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.Light.NoTitleBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.NoTitleBar" />

in values-v11:

<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.Holo.Light.NoActionBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.Holo.NoActionBar" />

in values-v14:

<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.DeviceDefault.NoActionBar" />

manifest file:

    <application
...
        android:theme="@style/Theme.NoBar" >

Everything is working excellent on android >4.0 but when I use 2.2 it doesn’t change theme – just font is getting white as it should be but there is no dark background.

I tried checking if it at least works and changed Theme.NoBarBlack in values (for android <3.0) and its value the same as Theme.NoBar and then when I pressed button font wasn’t changed -as it should do.

EDIT (PROBLEM FOUND):
So after trying it turn out that on Android 2.2 Manifest file set Background and rest, and programmatically changing theme affect only text color. any idea why that happens?

ANSWER (as I don’t have 10 reputation):
On android <3.0 it matters if

super.onCreate(savedInstanceState);

Is before setting up theme or not.

So it should be:

public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_NoBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lista);
}

Sorry guys for making problem out of nothing but as it was working on >3.0 I was confused. Spend half of day on it but working. 🙂

  • 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-06-12T14:31:03+00:00Added an answer on June 12, 2026 at 2:31 pm

    There’s a mistake in your styles.xml:
    for Theme.NoBarBlack, you set the parent to @android:style/Theme.NoActionBar, but it doesn’t exist.

    I think you mean @android:style:Theme.NoTitleBar.

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

Sidebar

Related Questions

I have some difficulties in my project. I got the RGB values from a
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I have some difficulties deploying my web app on JBoss AS 6.1. My current
I have some difficulties trying to run the python programs from cmd, or command-line.
I have some difficulties with understanding BindingSource's behaviour. Let's look at following example: Creating
I have some difficulties for using Ruby block, passing in a method. As in
I'm have some difficulties here, I am unable to successfully call a method which
I am new to programing and I have some difficulties getting AlertDialog working. I
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have had some difficulties in using extended classes in rails, in particular extending

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.