I've been trying out implementing navigation in android through navigation drawers and swipe views with tabs.
I've followed Google's developer tutorials (here and here) and for both situations I could never get my code to work unless I changed Activity or FragmentActivity to AppCompatActivity and applied other changes in the action bars code, for instance change getActionBar to getSupportActionBar so I don't get NPE.
Now the questions:
1- Why do I need to make these changes when I'm following official tutorials that should work the way they are?
2 - Is AppCompatActivity correct to use in these cases or is there a better way to do the same thing?
3 - Are these situations related to the min sdk and target sdk I chose? My min sdk is 14 and my target sdk is 22. Should I try to lower the target sdk?
4 - Are these situations related to the style/theme of my application? It's android:theme="#style/AppTheme" > .
Some insight on this subject is appreciated so thank you in advance.
Edit: Another thing I noticed is that I always need to import android.support.v7.app.ActionBar instead of android.app.ActionBar so I don't get NPE, even though my min sdk is higher than API 11.
Edit2: I noticed some contradiction in the developers' guides. Because I want to use ActionBar, I need to get my imports right. Following this link, it's recommended that I include v7 appcompat libraries, but following this one I need to import android.app.ActionBar because my min sdk is higher than 11. Like I said before, using android.app.ActionBar produces NPE, so what should I do?
Related
My app uses ActionBarActivity and ViewPager and I'd like to extend support to devices older than 3.0 (level 11 and below). However, when I try to add ActionBarSherlock as a library, my project goes to hell. Every reference to my projects R class is complained about.
I've read that this can be caused by multiple android-support-v4.jar files in the project. However, I seem to have a few and I'm not sure exactly how I should clean things up.
I think the easiest way is to post a picture of my Package Explorer. What do I need to delete or change to get my project working so that I can implement ActionBarSherlock and support older Android versions? Thanks!
Also, an Imgur link.
After some searching, I found a solution that appeared to work.
My project was complaining about my getActionView and getActionBar methods. This was solved by...
Replace getActionView with MenuItemCompat.getActionView.
Replace getActionBar with getSupportActionBar.
I have made a programm based on SDK 7. Now I want to add an Actionbar to it. I changed the minSDK to 11 in the Manifest. Isn't that supposed to change the design of the layouts I already have?
Problem is, that I get returned "null" by getActionbar(). I read, that I have to activate the title bar in the OnCreate of the mainactivity. But that does'nt change anything, still "null".
I can see the titlebar, but on SDK 7 it's smaller than on SDK 11. Can't really describe my problem. I just want to use Actionbar on my old written App. But the Layout still looks like in the pic below (left).!
LayoutProblems
Hope someone can help me.
Thanks!
You should also replace the old android.jar with the new one from SDK 11 to get the new GUI. If you are using eclipse for development, just check different Project buid target under Project - Properties - Android.
If you want to use ActionBar in older devices you must use actionbar support library which is provided with the sdk.
Need to create an application in a below mentioned link format targeting all the android platform i.e. from 1.5 to 4.1
http://natieklopper.blogspot.in/2011/08/iphone-styled-bottom-aligned-tab-bar.html
Can I use tab activity class for the same? Know it is deprecated but still need to confirm if we use then will my application work on all android devices.
Not getting appropriate demo or example to start my application with fragments,action bar sherlock's tab.
Please suggest me a simple way to initiate my application. Really appreciate if some examples are available.
Your application will work in all android devices if they have a newer version than 1.5
Deprecated means obsolete, but you can continue using ;)
I am new to android. My minimum API level needs to be 7, so that I can test the app on my htc hero. My target API level is 17.
The error concerns the actionbar. Some code is added by eclipse and I guess I need it to propperly run my app on the latest android versions:
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar() gives NPE on API 7, but not on API 17. How do I solve this without deleting the code (which I will presumably need for modern API levels)?
Basically, You need to follow this. If You need some good example, I think Android IO app source might be a good example on how to develop taking care about form-factor, API level etc. during runtime (however, it might be little bit difficult for completely new to android)
Action bar is not supported in any pre-honeycomb versions so any method related to action bar will not get executed....but after searching SO i came across this brilliant thing...
just check this out...
You can find out more information as well as screenshots of sample applications at link
The library is 100% open source and available at check this
from below question...
ActionBar pre Honeycomb
i think your device have android version 2.1 thats why you get error.
just add this actionbarsherlock lib to your Project.
after that just change this line
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
check this tutorials link and link
I am trying to use the BluetoothChat sample code as a base for an application I am working on. I don't understand why my android.app.ActionBar import isn't working. Eclipse doesn't seem to recognize it. My project build target is the Google API 2.3.1.
Can someone explain to me what I am doing wrong? I don't know how specific I should be so if more info would help you answer my question, please ask me.
android.app.ActionBar works only on 3.0 level 11 API
As mentioned in the android blog available here
Beginning with Android 3.0 (API level 11), the action bar appears at
the top of an activity's window when the activity uses the system's
Holo theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling
requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom
theme with the windowActionBar property.