android custom title bar in library - android

I created my own library with one activity and use it in another project. But when I create my own app theme with custom title bar for my activities in my project I have an issue. Activity from my library (of course) have default title bar. Any ideas how to solve it with the easiest way?

You could probably extend that Library's Activity and then set it manually. Check a similar situation somebody asked here

Related

Is there a way to set up an app bar/action bar in an Android app without going through the appcompat library?

I'm having a "this can't be right moment" trying to learn Android app development. I want to add some buttons to the top bar (app bar, toolbar, action bar, etc) of my Activity. Apparently this thing is called the app bar. But when I read the docs, I feel like I'm taking crazy pills:
This class describes how to use the v7 appcompat support library's Toolbar widget as an app bar.
Why do I have to use something called "appcompat" to add a toolbar? I don't care about backwards compatibility right now, I'm just coding an app to learn. Normally backwards compatibility shims/layers are an optional thing. I just want to do this in the most straightforward way at the moment - it'll be easier for me to learn that way.
There are other ways to implement an app bar—for example, some themes set up an ActionBar as an app bar by default—but using the appcompat Toolbar makes it easy to set up an app bar that works on the widest range of devices, and also gives you room to customize your app bar later on as your app develops.
Again, this sounds like the docs are saying that the method they advocate is not the simplest and most basic way, and that there's another. Then one of the very first steps in the tutorial is:
In the app manifest, set the element to use one of appcompat's NoActionBar themes. Using one of these themes prevents the app from using the native ActionBar class to provide the app bar.
Huh? So the first step to getting a toolbar is to turn off the toolbar? At this point I feel like I can hear clown horns going off. Am I being pranked? I don't think Google realize how bonkers this all sounds to a complete beginner.
Is there a way to add buttons/actions to the default Material UI ActionBar in an Activity, without going through the appcompat package?

Android - Remove completely ActionBar Sherlock (ABS) from project

I've implemented ActionBar Sherlock in my project, but now i would prefer to replace it with a simple custom layout bar and remove ABS completely from my project. I've googled it and couldn't find anything similar to this. I remember when i implemented ABS that i have deleted the default #libs. How do i completely remove it and implement back the previous stuff without messing up? Thanks
Firstly, let your MainActivity extends Activity instead of SherlockActivity..and then right click on your project goto properties->Andrioid..scroll down and remove ABS library and apply..In manifest if u have applied any theme then change it to #style/AppTheme..and that should be it..
I'm having the same issue. In addition to removing the ABS Library and extending MainActivity from Activity instead of SherlockActivity... you have to make sure all of your activities are switched. You also have to make change fragments as well. Any imports you have need to be changed as well (ActionBar, Menu, MenuItem, etc). I'd suggest in a separate branch deleting ABS and see where the errors are and go from there.

Custom titlebar (summary) in PreferenceActivity

As the title suggests I want to create a custom title bar for a PreferenceAcitvity.
I need to add a summary below the title. Currently it will only display a title, but I need a sub-title, just like any Preference can have a summary.
I have read loads of questions here, like this and this, but these all do something different; it's not possible to include a summary for the title with the first method. Creating a custom layout for every Preference also doesn't seem the wisest option, and is loads of meaningless work (I have tons of PreferenceActivity's. I am looking into extending something.
Also, I want to keep the default behaviour as much as possible, so I am looking into ways of adding a TextView to the default layout located in android-sdk-windows\platforms\android-16\data\res\layout\screen_title.xml
So I thought I would apply this layout to the method in the second Q, but now I run into the problem of resource id's used in the screen_title.xml file that aren't public.
I'm running out of ideas...anyone got some fresh ones?
EDIT:
I found a solution thanks to the accepted answer below.
To clarify a bit further: the method getSupportActionBar() in the answer isn't in the SDK, but comes from ActionBarSherlock.
This is a compatibility library to enable the ActionBar and FragmentActivity (amongst other things) on pre API 11 applications/ devices. It's quite a heavy library, around 11mb, so you will have to think about if it's worth adding 11mb to your application just to have a summary/ subtitle in your preference screen's. On the other hand, this ofcourse also allows you to implement the other features of the library, such as actually creating an action bar (and or menu).
If you are talking about Actionbar then you can do this:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setSubtitle("Test Subtitle");

Custom Title bar & Tabs

Is there any way to change the content of the title bar when it's in Tab(If it wasn't in tab I would have done it but tried couldn't find any solution). E.g. Suppose I have created a custom title bar with few buttons on it, and now I want to change the content of the title bar(Drawables, Title and the functionality).
It would be great if someone could tell me if i can implement Action bar in versions below 3.0 ? I am creating this project in 2.1 (I'd like to create action bar from scratch).
or if there's any way beside inserting an image and placing buttons on it(This methodology would be good enough)?
If you're just looking to implement the ActionBar paradigm in pre-Honeycomb versions of Android, I suggest you look into using the ActionBarSherlock library.
The library will automatically use the native action bar when
available or will automatically wrap a custom implementation around
your layouts. This allows you to easily develop an application with an
action bar for every version of Android back through 1.6.
twaddington and pjco's answers are correct, you need to use ActionBarSherlock if you want to be compatible with every SDK levels.
I want to add you can have a custom actionbar or a custom view for your actionbar tabs using the method actionbar.setCustomView(view) or tab.setCustomView(view)
Anyway, play with ActionBarSherlock demos, there are a few cool use cases.
The other option worth looking at is ActionBarCompat, which I think comes with the SDK 14 api demos. However, ActionBarSherlock seems to support many more features so that may be the better solution.

Applying a custom title bar for the entire application

I actually want to apply a custom title bar (kind of like the Action Bar), but since i'm developing for Froyo, I actually need to have it in a xml file. The trivial way to do this is to just write the code to create the title bar in each of the activities.
I did search around for some efficient ways and found this on SO
Similar Problem
There are 2 solutions proposed over there, but I am having problems in implementing them.
To include the layout of your title bar in the layout of all the Activities. My question is say I have a sample layout as follows, where should the include tag go and do I need to use Theme.NoTitleBar theme for the application in order to get it working?
To subclass Activity and then derive all of my Activities from that. Should the custom Title bar creation method be defined in the onCreate method of the subclassed Activity. Because if I do this, the custom title bar does appear, but it appears blank. No buttons,etc.. are present on it.
Thanks in advance for any help you provide
The tag belongs inside the top level view container (linear layout/relative layout). Yes use NoTitleBar so you don't have the Android provided title bar in your app window.
There is obviously an issue with your code there, with out any code in your post I cannot help you.

Categories

Resources