0

I'm using a custom background for my ActionBar. I followed the tutorial from here.

My styles.xml looks like this:

  <resources>
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/actionbar_bg</item>
    </style>
</resources>

I want this ActionBar to be displayed on each activity, except the login .. so I hid the ActionBar from my login activity (tut from: stackoverflow):

public class Login extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    actionBar.hide();

In my manifest I added the custom theme ... like this:

 <application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:theme="@style/MyTheme"
    >

When I run the application, I get the error: You need to use a Theme.AppCompat theme (or descendant) with this activity

So I searched on stackoverflow for a solution. I had to extend Activity instead of ActionBarActivity. I did this, also on my Login Activity.

But now ... I can't hide the ActionBar anymore at my Login activity because it doesnt extend ActionBarActivity anymore .. so the following code:

   ActionBar actionBar = getSupportActionBar();

Won't work .. anyone have an idea how to still Hide the actionbar at the Login activity, but still with a working custom Actionbartheme?

TL;DR: I want to use a custom actionbar, but I want to hide it on my Login activity. I can let the actionbar work, but only If I let my Login activity extend from Activity, instead of ActionBarActivity - This causes the getSupportActionBar(); to stop working, So I can't hide the actionbar anymore.

Community
  • 1
  • 1
  • 1
    You don't need to hide, just use another theme for your login activity. I'm trying to use support lib everywhere, so I use `Theme.AppCompat.Light.NoActionBar` as my parent theme and set Toolbar as my action bar where I really need it :) – Viktor Yakunin Mar 29 '15 at 16:52

2 Answers2

0

Create a theme whose parent is Theme.Holo.Light.NoActionBar. Assign it to your login activity with android:theme parameter.

Lamorak
  • 10,957
  • 9
  • 43
  • 57
  • Worked perfectly, have been struggling for hours now. I will mark this answer as correct (4 Min remaining). Thanks ! –  Mar 29 '15 at 16:53
0

Just add below code in onCreate Method before setContentView() method :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // add this line

    setContentView(R.layout.login_layout);
Pankaj
  • 7,908
  • 6
  • 42
  • 65