Android theme in library project - android

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.

Related

AppCompatActivity: manually add Toolbar or use a theme with ActionBar?

What is the difference between the two following approaches of having an action bar in an Activity?
Manually use Toolbar
Set the app's theme to Theme.AppCompat.NoActionBar and then include a Toolbar manually into the layout like this:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar" />
In code then use AppCompatActivity's setSupportActionBar() method to use the toolbar.
Use a theme with action bar
Set the app theme to Theme.AppCompat.Light.DarkActionBar (or any other theme with action bar) and don't include a separate Toolbar into the layout. In the debugger I can see that the resulting action bar is an android.support.v7.app.WindowDecorActionBar. Checking the source code of it, I find that it at least "knows" about Toolbar.
My questions are:
In both cases I can use the Activity's callbacks to populate the actions, to get information about a tapped action/option etc. Also the visual appearance seems to be identical. Which makes me wonder...
What is the correct approach?
Is the theme based approach also using the Toolbar or is it something else?
Advantages of either approach?

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.

Hiding the action bar

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.

ActionBarSherlock doesn't show ActionItems when using dialog theme

I am trying to update my app with the new ActionBar paradigm. I want to keep compatibility backwards though, as my largest user base is still on Gingerbread.
To that end, I am trying to integrate ActionBarSherlock into my app.
My app is designed to use the dialog theme, so when I integrated ABS, I tried to use the corresponding dialog theme as so in my AndroidManifest.xml:
<application android:theme="#style/Theme.Sherlock.Dialog" >
My ActionItems would not show up though, and only appeared as old-school menu items (meaning they were completely inaccessible on my tablet). Looking at the samples in the ABS download, I decided to try changing my app and removing the .Dialog qualifier, changing my AndroidManifest.xml to:
<application android:theme="#style/Theme.Sherlock" >
Once I did that, the menu items moved from the menu to the ActionBar, where I expected and want them to be. So it would seem that, with default conditions, ActionItems are not enabled when using the .Dialog theme.
Is there any way to enable this behavior, so that the menu items would show in the ActionBar as expected while still using the dialog theme?

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