implement action bar on android API 7 - android

I am working on Android 2.1 with API v7.
How can I implement the action bar in this old version API which can work like built-in ActionBar on devices supporting API 11 or greater? Is there any support package ?
(A good tutorial on how to implement action bar in old version API is appreciated)

Here is an examle of adding actionBar with slides menu to api>7:
https://github.com/BradleyRL/NavDrawerExampleAppCompat-v7
It's documented here for api>14 http://developer.android.com/training/implementing-navigation/nav-drawer.html. (first link - is upgraded method of second link to support previous versions).
Then, you could read documentation here: developer.android.com/guide/topics/ui/actionbar.html
To do this this way you must add project library to your project (and for exammple in 1t link too).
To do it: File>New>Other>Android Project From Existing Code>Browse (Select "YOUR_PATH_TO_ANDROID_SDK\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\extras\android\support\v7\appcompat"), check adding it to workspace>Finish.
Then go to properties of your(example in 1st link) project>android>add (choose this library)>OK.
And you must extend your main class from ActionBarActivity insted of Activity. I try this, and it work on 2.3.7 and on 4.1.1 versions)
Hope it helps)
P.S. Sorry for my bad english and hi from Russia)

You can/should use this ActionBar project.
It's very very simple to use and I am using it myself in one project.

Related

ActionBar does not work, Android

I have a problem with ActionBar.
I set minsdk in AndroidManifest to 14. Next I create Activity (BlankActivity), thats create MyACtivity class which extend ActionBarActivity and import android.support.v7.app.ActionBarActivity. I think that this library need only if you use sdk level 7 or lower.
This import correctly? Or i need use another extend class?
And I try change extend class to Activity, but its does not create ActionBar on Activity.
How add ActionBar on this Activity?
P.S. I was misled, because on my sdk function getActionBar must work, its NullPointer, because my app use this strange import. A can use getSupportActionBar, but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
P.S.S. Thanks!!
If anybody have same problen, there is some links about toolbar:
http://www.101apps.co.za/index.php/articles/using-toolbars-in-your-apps.html
Why was ActionBarActivity deprecated
I have a problem with ActionBar.
Who doesn't ;)
I think that this library need only if you use sdk level 7 or lower.
The appcompat-v7 library used to backport API 14 Action Bar to platforms below that. APIs 7 through 13 used this reimplementation, APIs from 14 used native Action Bar.
Since Lollipop the appcompat-v7 always uses it's own implementation of Action Bar and backports Material theme from Lollipop.
This import correctly? Or i need use another extend class?
To have the Action Bar with appcompat-v7 your activity class must extend AppCompatActivity (previously ActionBarActivity) and it's theme must descend from Theme.AppCompat.* family.
And I try change extend class to Activity, but its does not create ActionBar on Activity.
Native activities on Lollipop don't have any Action Bar by default. You would supply it by having a Toolbar widget in your layout and calling setActionBar(Toolbar). Similar approach can also be used with appcompat-v7 (if you use a theme without default action bar) by calling setSupportActionBar(Toolbar).
How add ActionBar on this Activity?
[...] but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
It's perfectly OK, the goal is to make the app look the same from API 7 to API 22. Appcompat-v7 now backports not only the Action Bar but Material theme as well.
It's better you start with a working example. Just check in you android sdk installation for the folder \samples\android-21\ui\ActionBarCompat-Basic.
The use of the support library is correct, just follow the ActionBar Developer guide here.

Can i use search view for API level 8

I was trying to use search View in my application but it showed an error i.e View require API level 11(current minimum is 8).
Is there any method through which i can use this search view by keeping min API level to 8 only?
If there then provide a small code snippet.
Thanks
As you can see in the documentation, the SearchView is added in API level 11. If you want to use it below that, use the Support Library: https://developer.android.com/reference/android/support/v7/widget/SearchView.html
See also this post.
The entire searchview code is available here with Minimum Required SDK : API 8 : Android 2.2 ( Froyo )
you can use the support library of API 11 and include it in your project in order to use it's components.
you can use sherlock action bar lib.for do this task please refer this link..
How to implement search widget in Action Bar Sherlock?
You can use the v7 appcompat library for a backwards compatible SearchView. You should prefer this library over action bar sherlock, as the former is Google's own implementation and I believe action bar sherlock is no longer being actively maintained.

How to do the compatibility mode for below android versions?

I am developing a android application.i am using action-bar in my app.but its not working in my Android smartphone(2.2.3) crashing. give me the solution.
Use actionbar sherlock for supporting lower versions too.. follow this
Here is how to use ActionBarSherlock:
Download the ActionBarSherlock here.
Assuming you're using Eclipse IDE, right click your Project, click Properties, then Android. At the bottom, in Layout, Add ActionBarSherlock.
Make sure ActionBarSherlock and your Project are in the same directory.
Extend your classes to Sherlock naming. For example, instead of Activity, change it to Sherlock Activity. The main documentation of ActionBarSherlock is found here.
For easier usage of Sherlock, create util methods in changing the Sherlock names and modifying it.
If you just need to know ocally the android version and act according to it :
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// do something
}
else {
// do something else
}

setDisplayHomeAsUpEnabled in Compatibility Library

In my app I have a some fragments that I switch between manually in the phone version and I want to show the < arrow in the ActionBar. To do this I know I need to call actionBar.setDisplayHomeAsUpEnabled(true); but that breaks in lower api levels. I can check the api level and only call it in 3.0+ but LINT gives me an error. Is it alright to just suppress the error? What's the right way to do this?
First setup ActionBarSherlock for compatibility for Android 2.1+ for the ActionBar:
http://actionbarsherlock.com/
https://github.com/JakeWharton/ActionBarSherlock
One you have set up this great compatibility library, you can now use in your Fragment:
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(true);
Make sure you extend your Fragments to SherlockFragments:
public class TestFragment extends SherlockFragment
If you need anymore help, let me know I have set this up many times!
Regards,
Use Jake Wharton's action bar sherlock library which is more flexible to support in all versions.
https://github.com/JakeWharton/ActionBarSherlock
If you need use the actionbar in android 3 and higher only, you can suppress warnings (be shure that min api level is set). But else you have to use SharlockActionBar library.

Android customize action bar with api<11

how can I customize my action bar with api<11? I can't use actionBarSherlock because I got an issue related to my custom rom...is there a way to do that?
You can go For sherlock Action bar. here is link for the same
Here is detailed info on how to implement it
Make sure your project uses Android 4.0+ as the build target and that
you have the compatibility/support library added. (You can
right-click the project, select Android Toots > Add Support Library)
Download the ActionBarSherlock library project and import it into
Eclipse.
Right-click your main project, select Properties, and select Android
in the left pane. In the bottom half of the window, click the Add
button and select the ActionBarSherlock project. Click OK.
Instead of using regular Activities and Fragments, you use ones from
the Sherlock Library. They have the same names, but prefixed with
"Sherlock" (SherlockActivity, SherlockFragment, etc.)
To access the actionbar in code, you call getSupportActionBar(). This
returns either the regular actionbar (for Honeycomb and later) or the
Sherlock actionbar (for pre-Honeycomb).
Theming instructions are on the ActionBarSherlock website.
You can set android:minSdk in android manifest to lower sdk say 2.2 but built have to build in target 4.
So, it will work on handsets with api level < 11.
Hope it helps.
You have to write your own ActionBar

Categories

Resources