0

I use the actionbarsherlock with tabs on my app. On the tabs is must change the textcolor in black or white. According as in which orientation my app is. Is it on landscape I must change to white. Because my actionbar is black. When I change to portrait I must set so black cause my tabs background is white. But you can use programmatically to change the color. So I use the trick to change the theme.

I have disabled the reload option when the orientation change on my manifest via

android:configChanges="keyboardHidden|orientation|screenSize">

This works god. Now I implement this on my fragment:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);

    if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
    {
        getSherlockActivity().setTheme(android.R.style.Theme_Holo_Light);
        Log.e("Portai", "port");
    }
    else
    {
        getSherlockActivity().setTheme(android.R.style.Theme_Holo);
        Log.e("land", "alnd");
    }
}

The log can I see on logcat. But the theme isn set. The tab font color is always on black! can anyone help me to setTheme so I can change the text color on tab programmatically

5
  • 3
    Handling configuration changes yourself is something you should only do in rare circumstances. You are better off defining a new theme in your styles.xml in a resource directory qualified for landscape configurations (like /values-land or /values-v11-land).
    – Karakuri
    Jan 15, 2013 at 16:47
  • 1
    The theme needs to be defined before the layout is created on the screen, which means if you disable the recreation of the activity you cannot have a new theme. Follow Karakuri's recommendation.
    – Murphy
    Jan 15, 2013 at 18:52
  • thank you, thats is! but how can i do that my app do not refresh itself? It is an SherlockFragment and the onCreatedView was loading again. That isnt what i want
    – StefMa
    Jan 16, 2013 at 12:55
  • Check this out: stackoverflow.com/questions/7800974/…
    – Saran
    Jan 16, 2013 at 15:47
  • Did you try my answer? Let me know if it helped you, please.
    – Saran
    Oct 24, 2013 at 18:13

1 Answer 1

0

Another way would be not to override config changes (for activity) and to check for orientation on Fragment creation, like this:

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(this.getClass().getSimpleName(), "onCreate()");

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
      getActivity().setTheme(android.R.style.Theme_Holo_Light);
    } else {
      getActivity().setTheme(android.R.style.Theme_Holo);
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.