Hiding the action bar - android

It is a sample on the book.
I'm trying to hide the action bar by setting the theme to Theme.Holo.NoActionBar:
<activity
android:theme="#android:style/Theme.Holo.NoActionBar"
... >
...
</activity>
However, when I tried this I get the following exception:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
What does this mean? How can I get around this?
I'm new to android programming.
Thanks!

I believe this message is because you're using a compatibility library, or you've set your minimum SDK level too low. Basically the Holo theme didn't exist in the API version you're trying to maintain compatibility with.

ActionBarActivity requires a Theme.AppCompat theme as it assumes you want an Action Bar (hence its name). If you do not want an action bar, your activity should extend from FragmentActivity which contains everything but the Action Bar from ActionBarActivity. Then you can use Theme.Holo.NoActionBar without issue.

Related

ActionBar menu icon not showing [duplicate]

I am building an Android app and want to have a button always visible on the actionBar. I followed this guide and others, but none of them seem to solve my problem (although they are very close I guess...).
I have the package "app" and use app:showAsAction="always". No error is shown, but no button on the bar as well. When I change it to android:showAsAction="always" the button appears on the bar, but AndroidStudio tells me I should go for "app:showAsAction with appCompat...".
I have a custom theme with parent="#android:style/Theme.Holo.Light.DarkActionBar"> and for the bar itself: parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">.
Should I change something and get app:showAsAction working, or ignore AndroidStudio error message and go for android:showAsAction?
This is the documentation of the lint rule:
AppCompatResource
Summary: Menu namespace
Priority: 5 / 10
Severity: Error
Category: Usability
When using the appcompat library, menu resources should refer to the
showAsAction in the app: namespace, not the android: namespace.
Similarly, when not using the appcompat library, you should be using the
android:showAsAction attribute.
I think the problem is that you are mixing Framework Activity and AppCompat menu.
You should use AppCompatActivity with AppCompat Action bar and app:showAsAction; or Activity with android:showAsAction.

Android theme in library project

I have a library project providing a few activities. Some are immersive, and I need the action bar to be created. On the other hand, the clients using the library must be able to customize its theme (mainly the colors).
One of my clients is using the Theme.AppCompat.Light.NoActionBar theme, which removes the action bar from my activities.
Is there a way to ensure that the action bar will be shown (so, my activities' themes have to inherit from Theme.AppCompat.Light.DarkActionBar), while leaving the colors customizable?
Programmatically creating the action bar would be fine, but I'm not sure that this is possible, right?
EDIT: It works if my client declare the library's activities in their manifest, and set a DarkActionBar theme on each. But I'd really prefer to avoid that solution, as currently they don't have to declare our activities thanks to the manifest merger.

Show activity below status bar without access to activity XML/code

I have used Theme.AppCompat.Light.NoActionBar in my styles.xml to remove the action bar in my Android application. In all activities, I'm including a toolbar instead.
I am using a third party library (http://kokum.io) for user login in the app. I do not have control over the activity XML or code for the login screen that the library uses for authentication. The top of this activity is going behind the status bar.
Is it possible to make the activity show up below the status bar without access to the activity code/XML?
I figured out the solution.
In AndroidManifest.xml we can specify themes specifically for each Activity.
<activity
android:name="io.kokum.integration.LoginActivity"
android:theme="#style/CustomTheme" />
This can override the app level theme specifically for this activity.
In the specific case above, I was able to use a theme that provides an action bar to fix the issue.

NoActionBar equivalent on Sherlock ActionBar

I want to hide the action bar of my activity. If I were to do it using android's libs I guess that this line on the manifest would do the job:
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
But I don't want to limit my app for Android 3.0 so I'm using Sherlock Actionbar. What do I have to do to achieve the same effect on it?
Thanks
If you just want to hide your ActionBar use this : getSupportActionBar().hide();
or you can set Theme.Sherlock.Light.NoActionBar as theme of your Activity.
Set Activity theme to one of the following and it will work fine
android:theme="#style/Theme.Sherlock.Light.NoActionBar"
android:theme="#style/Theme.Sherlock.NoActionBar

Honeycomb Action Bar not showing (baffled)

I am completely baffled. I created an application with minSDK=4 and targetSDK=11. Compiled and ran on the Xoom tablet. I am not getting an Action Bar and cannot figure out what I have done wrong. I have been staring at the screen for hours and don't know what I have done that would have caused the bar to disappear. Help! Any suggestions on why I am not seeing the Action Bar?
You need to declare android:theme="#android:style/Theme.Holo" for Activity in Manifest xml.
The dev guide says like you only need to set the target SDK version, but it does not work.
I'm quoting from here:
"If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher)."
I used android:theme="#style/Theme.AppCompat" in my manifest and the action bar appeared.
Romulus' answer, forcing the App to use the Holo theme will work but it results in a compile error if your minSDK is less than 11.
Check if you have defined a theme in the AndroidManifest:
android:theme="#style/XXXXXXXXXXXXXXXXX"
That means you're forcing the App to use a particular theme, so the action bar might not appear on Honeycomb or higher devices (it depends if the theme specifies an action bar). Delete this statement to cause the App to use the default device theme, so the Settings menu appears on pre-Honeycomb devices and the action bar appears on post-Honeycomb devices. Job done. Hope this helps.

Categories

Resources