ActionBar does not work, Android - 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.

Related

Can I use AppCompat theme with Activity/FragmentActivity classes?

Given the following:
Android documentation says :
AppCompatActivity - Adds an application activity class that can be used as a base class for activities that use the Support Library action bar implementation.
I'm not considering adding action bar to my activity
I need some material design widgets, which I can control only through AppCompat or material theme, but the latest need API >= 21, which is not my case.
I tested Theme.AppCompat.Light.NoActionBar with Activity class and it works well.
--
Is there an issue with using Activity class with AppCompat theme in my case?
The AppCompat library is intended to make compatibility with olders API, so the Theme and all components may work well in older systems.
I think the only concern is to always use the AppCompat elements and not the regular ones.
Example, use AppCompatEditText, AppCompatTextView, etc... And always refers to they with the AppCompat (AppCompatEditText editText;)
I have used a lot the support library and not have others issues, considering the visual elements may be a little different when using an API minor than 21
No.There is not issues with AppcompactActivity & support libaray. You can refere this link
To gain more rich & amazing look go with support library,Try to do material design

Should I use AppCompat v7 if minsdk is 14

should I still use app compat v7 if my app has minSdk = 14?
Is there any advantage with ActionBar in Android L ?
Should I use android.support.v4.app.FragmentActivity from support v4 or should I use the android.app.Activity class (which has support for fragments since honeycomb)?
Should I also use android.app.Fragment or android.support.v4.app.Fragment?
I guess that I should use support v4 FragmentActivity and Fragment, but there is no need for app compat v7, right?
What do you think?
If you want to use Material Design style for SDK 14+, you should also use AppCompat v7:21.0.+
You app can use Material as its main theme, and functional from API 7.
More info you can check this link
AppCompat is used for api level below 11. Since 11 you have action bar natively. So there is no need to use AppCompat on api levle 11 and above.
Extend Activtiy and use Fragment ( not android.support.v4.app.Fragment)

Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each other in terms of usage?
extending ActionBarActivity gives you the ActionBars functionality on every API level >= 7
by extending Activity you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar on api levels below 11
edit: More details:
ActionBarActivity is part of the Support Library. Support libraries are used to deliver newer features on older platforms. For example the ActionBar was introduced in API 11 and is part of the Activity by default (depending on the theme actually). In contrast there is no ActionBar on the older platforms. So the support library adds a child class of Activity (ActionBarActivity) that provides the ActionBar's functionality and ui
edit2: Update April 2015 - it looks like the ActionBarActivityis deprecated in revision 22.1.0 of the Support Library. AppCompatActivity should be used instead.
edit3: Update Aug 2017 - LifecycleActivity is a LifecycleOwner but:
"Since the Architecture Components are in alpha stage, Fragment and
AppCompatActivity classes cannot implement it (because we cannot add a
dependency from a stable component to an unstable API). Until
Lifecycle is stable, LifecycleActivity and LifecycleFragment classes
are provided for convenience. After the Lifecycles project is
released, support library fragments and activities will implement the
LifecycleOwner interface; LifecycleActivity and LifecycleFragment will
be deprecated at that time."
(copied from the Architecture Components guideline)
If you look carefully, you will see this
public class ActionBarActivity extends FragmentActivity
implements ActionBarDrawerToggle.DelegateProvider TaskStackBuilder.SupportParentable
Here you can read about FragmentActivity:
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
And differences between Activity and FragmentActivity:
Difference between Activity and FragmentActivity
Also, there are some new themes for styling actionBar...
https://developer.android.com/training/basics/actionbar/styling.html
Actionbar is introduced in API level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below. So, if you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.
If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.
Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.
The ActionBarActivity or the SupportActionBarActivity have additional methods and properties that are not in a generic Activity. for example methods for adding tabs are present in the ActionBarActivity and not in a generic Activity.
The major difference being you don't get an ActionBar on a generic Activity.
ActionBarActivity just has more support libraries and better usage of the newer themes available from api 11.
"In its most basic form, the action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app."
You are using Android support library When you come to to the Actionbaractivity . so the uses of Support library is your application can be suport for maximum number of devices. Support library gives to your application the power of Backward compatibilty. Actionbaractivity gives you the mulitiple feature like Actionbardrawer toggle etc.. there are more support libraries available. see this link .. and share to your friends...https://developer.android.com/tools/support-library/index.html

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.

implement action bar on android API 7

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.

Categories

Resources