I am using the deprecated Tab Bar at the bottom of my App. an example of my Tab Bar.
Then I used the ActionBarSherlock
at the top of my Application. It works pretty fine for Android v2.3.5 and version3.2,
but when I run it on Android v4, the ActionBar
disappear, and items on ActionBar
appear as option-menu and the sub-menus appear as context-menu.
I can not change the architecture and use fragment instead of deprecated Tab Bar.
Do you have any idea how can I make the ActionBar
appear in Android v4 ?
Or do you think it is impossible since I can not use fragment in this case.
public class MainActivity extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Styled);
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
System.out.println("Hello");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
And style.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="titleTextStyle">@style/TitleText</item>
<item name="android:titleTextStyle">@style/TitleText</item>
</style>
<!-- Title on action bar -->
<style name="TitleText" >
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">12.5dip</item>
</style>
</resources>
First of all in your application it's better to use SherlockFragmentActivity
and SherlockFragment
as it's content. At least in my opinion. Second on early versions of Android the actionbar items will be shown only when you set this value for them : android:showAsAction="always"
.
For example :
<item
android:id="@+id/sync"
android:orderInCategory="1"
android:title="Sync"
android:icon="@drawable/ic_action_refresh"
android:showAsAction="always" />
In devices which has hardware menu button, the rest of elements will be places as sub-menus even if the android which you are running the app is 3+.
Using deprecated TabBar is not a problem for you, but there is a good example on how to use tabs with ActionBarSherlock
using Fragments
which you can find here : FragmentTabManager