Android Tab ico in API 16 - android

I have an app with 4 tabs and icon images for each tab. I am using TabActivity and TabHost.
setIndicator ("Example", getResources().getDrawable(R.drawable.tabicon));
The app works fine with API 8 and when I have the following in the manifest file :
but when I explicitly put the targetSdkVersion="16" in the manifest, the tab icons are not showing.
How can I preserve the Tab icons without changing a bunch of code? Is there a Tab icon code sample I can follow for API 16?
thanks a bunch !!

TabActivity and TabHost are deprecated in API 11.
Instead use the ActionBar with Tabs (Example here), for compatability with API versions lower than 11 use ActionBarSherlock.
Don't use old APIs anymore!

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.

developer.android.com training actionbar - correct result?

I am currently following the tutorials on http://developer.android.com/training/index.html.
I have completed the first section and continued the second section on the same code.
In the tutorial the goal is to make an ActionBar.
I have chosen to support android 2.1 and above using the v7 appcompat library.
I assume it is installed correctly (and have followed this thread).
My question is, what is my result supposed to look like?
I have created 2 AVD's, one running API 18 and one running API 8 and am testing on my own phone (Xperia Ray running Cyanogenmod 9, which is API 15 I believe)
All 3 devices give different results.
The AVD running API 18 shows the app with an actionbar in both the main activity and a secondary activity. Pressing the logo in the Actionbar in the second activity returns to the parents activity.
The Xperia Ray phone (API 15) also shows the actionbar in both activities but does not return to the parent activity after being pressed. I suppose I still need to program that and is not standard in API 15?
The AVD running API 8 shows an actionbar in the main activity with the name of the app but shows no actionbar in the second activity.
This is the code I used, from the tutorial linked above:
public class MainActivity extends ActionBarActivity { ... }
and in the manifest in the < application > tag
android:theme="#style/Theme.AppCompat.Light"
Should this be enough to make an actionbar appear in lower versions of android or is it supposed to not show an actionbar besides the main activity in lower versions?
I'd like to fix this before continuing the tutorial.
If my question needs more clarifications, I'd be happy to provide it. All help is appreciated. Thanks!
I have no experience with AppCompat, but I recommend ActionBarSherlock appCompact, is very easy to use. Link: http://actionbarsherlock.com/
You can also customize the style with: http://jgilfelt.github.io/android-actionbarstylegenerator/
good luck ;)
I found what I did wrong.
Following the tutorial litterally, the second activity will not have an actionBar.
In each of the activities java file, the class must extend ActionbarActivity instead of Activity. (The tutorial only explicitly tells to change the main activity)
--> This makes an action bar appear in every activity.
To make the back or home button appear in all versions, I did it like this:
//Make sure we're running on HONEYCOMB or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT >= 7 ) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //for older versions
//getSupportActionBar().setHomeButtonEnabled(true); //without arrow
}
The first if statement should already be there by default (I commented it out as it was left out some of the code examples in the tutorial. Leave it in!).
getSupportActionBar() needs to be used on older APIs (make sure the appcompat library is included correctly). Using getActionbar() on older APIs causes a Forced Close.
Using setHomeButtonEnabled() works too but is without the < icon in the action bar.
Thank you for the replies. If anyone has other suggestions or tips, they are always welcome. (are both if statements needed?)

Stacked ActionBar tab bar not filling parent

I'm creating Action Bar navigation tabs, but when the Action Bar is stacked the tabs are not getting the whole width space. I have a foto to illustrate it.
Is possible, in this case, giving to each tab 50% of the screen width?
Thank you
I'm editing to say that it's not a Sherlock Action Bar. And I'm working in a Samsung Galaxy Note 10.1 and in a Nexus 7. And now, testing it in the Nexus, I noticed that it's behaviour is different. Another screenshot:
I don't think that's feasible at the moment. I've been trying to do the same thing for the past few days, and here's what I have found so far.
The Android framework uses a class called ActionBarPolicy to set some rules regarding the ActionBar's behavior.
In this file (which can be found here : https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/view/ActionBarPolicy.java), you'll find a method called getStackedTabMaxWidth() which returns a dimen value (currently set in the ressources at 160dip).
This value is used is the inner class TabView placed in ScrollingTabContainerView (https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/widget/ScrollingTabContainerView.java). TabView is the private implementation of the ActionBar's TabBar.
Now I don't think this value nor this behavior can be modified, except maybe using Reflection. I don't know enough about it to do so, so if someone could manage such a thing, don't hesitate to say so, because this really is a bad behavior which doesn't look great on some tablets.
Android stacked action bar tabs do not have adjustable widths.
"Stacked action bar tabs now have a width limit. This prevents super-wide tabs that can span the whole screen. The cluster of tabs is centered if it does not span the full width. " https://android.googlesource.com/platform/frameworks/base/+/b8139af3dcae80c0030afd0354dc424a7c72c3d9
The solution is to use the TabLayout API from the Android Design Support Library released with Android 5.0. The Android Support library requires the appcompat library, but that dependency is resolved for you if you build using gradle.
For most developers, this will not be an issue, but the TabLayout setup requries at least SDK API level 22, because the appcompat dependency is compiled against 22. However, TabLayout does not have a runtime dependency on 22, meaning you can run it on devices up to API level 7.
tl;r - Use Tablayout from Android Design Library. Requires API level 22 on developer, but can run on older phones up to v7.

How to create Android tabs like this (screenshot)?

Any idea how to implement tabs like these (the one on top with home image, star, etc)
Using tabs in an action bar on Ice Cream Sandwich.
Or ActionBarSherlock tabs for a full on backward compatibility.
Those are so-called "swipey tabs", probably on top of a ViewPager. ViewPagerIndicator has an implementation of such tabs.
if you wish to use the same tabs-pager like on the android market app (aka google play) , you can get the android support library from the sdk manager and see their sample on ".../extras/android/support/samples/Support4Demos" .
there , find the fragment example called "tabs and pager" . i think you will like it ... :)
Try this. The solution there is to use the setDividerDrawable(...) method of the TabWidget class. Then you can define the looks of the tabs with XML.

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