actionBar = getActionBar(); is working fine In most of the new mobile sets, but in some old set it give error -
"application stopped unexpectedly"
Can somebody please tell me why it is so, or is there any alternatives for getActionBar(), like actionbar = new ActionBar(). I am not using support.v7
Start using v7 appcompat library, as it is the only way.
Read this : https://developer.android.com/topic/libraries/support-library/features.html#v7
Add this line in the build.gradle and re-sync:
compile 'com.android.support:appcompat-v7:23.2.0'.
Refractor your activity classes by extending to AppCompactActivity instead of Activity.
If you've set custom action bar, call setSupportActionBar([your_custom_toolbar]) in OnCreate() method.
You can now call getSupportActionBar() error-free :)
in your onCreate() function use this line to set your ActionBar.
getSupportActionBar().show();
Hope it solves the problem!
Older devices that you are using don't have the ActionBar; so the application crashes when you try to access it.
So, to support ActionBar on older devices, you can use the support library and use getSupportActionBar() to access it.
Instead of using the plain vanilla Activity, you should be using ActionBarActivity to be able to use the getSupportActionBar() method.
Related
My custom factory isn't getting called in ActionbarActivity anymore with AppCompatDelegate as of v22.1.1.
I see in the docs that in this case you shouldn't call AppCompatDelegate.installFactory() (and a custom activity seems to support this) but if this is the case then I can't use AppCompatActivity/AppCompatDialog (and possibly the new builder?) or anything that inherits from those classes. So basically I need to reimplement the non-material versions (ie actionbar parts) of AppCompatActivity.
Is this actually the case or am I doing something wrong?
Using android.support.v4.view.LayoutInflaterCompat solves the problem.
I am making an app which should have minSdk = 15 and targetSdk = 21, therefore I want to use the features provided by the appcompat-v7 library.
I always wondered if I should use getFragmentManager or getSupportFragmentManager when using the supportlibrary-v7.
I am encountering a small problem now: when using getFragmentManager (and therefore using the framework fragments and fragmenttransaction) I wasnt able to pop the backstack by simply pressing the backbutton - I had to do a backStackCount > 0 check and manually popBackStack, otherwise my activity was simply finished. This problem was solved when I switched my small app to use the v4 classes (getSupportFragmentManager etc.). Which is fine I guess, but I would like to have a guideline/bestpractice to know which way to go and why
So, my Activity is inheriting from ActionBarActivity (according to AppCompat-Blog-Entry) and I am using the new toolbar, should I use only v4-Fragments(-Manager, -Transactions)?
I havent found any best practices or guidlines for that. And I am unsure about what to consider when deciding between these two :-/
If you are inheriting your activities from ActionBarActivity you should always use getSupportFragmentManager(). It automatically forwards your calls to getFragmentManager() if the phone supports it (runs Honeycomb or later), otherwise it uses its compatibility implementation.
I wrote a sample application for the NavigationDrawer pattern with the ActionBar-Compat library project. Every time i change from portrait to landscape mode i got a NullPointerException during onAttach(). The Activity returns null for the getSupportActionBar() method. This happens in the Fragment which is changed by the NavigationDrawer. You can find the code on my github project: FadingActionBar-Compat (Line 162)
Maybe it is a error which can be fixed by a update from google in the future?
I found the solution by looking in to the ActionBar Compat source code. The ActionBar is ready to use in the lifecycle methode onActivityCreated(). You musst call the super-Method before. After that you can call getSupportActionBar() without a NullPointerException.
I'm look for the easiest way to get an ActionBar instance from a Fragment using AppCompatLibrary and API 8.
Already tried things like
getActivity().getSupportActionBar()
but no luck.
Try to cast it:
((YourActivity)getActivity()).getSupportActionBar()
I just added ActionBarSherlock to my project using these instructions, and the project compiled. But I haven't been able to actually use the library. Trying to use getSupportActionBar() just yields a Cannot resolve method error.
I'm referencing the library at the top of the class. Actually, import com.actionbarsherlock.app.ActionBar and import com.actionbarsherlock.* came up in the suggestions dialog, but I've tried both separately, and both come with the warning Unused import statement. So it seems my project doesn't actually know there's a connection between getSupportActionBar() and the ActionBarSherlock library. Any ideas on why/how to fix it?
I bet that you extend an Activity and not a SherlockActivity
Also do not forget to use a Sherlock Theme