I am working on an Application in which I have to use the Action below 3.0 also. So I am using Sherlock Library for this.
But its getting very tough to use this library as I am unable to catch few important events like I want to use the ActionBar & TabFragments on my screen for which I have edited the code and used it like:
public class TabNavigation extends SherlockActivity implements ActionBar.TabListener {
private TextView mSelected;
ActionMode mModes;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_navigation);
mSelected = (TextView)findViewById(R.id.text);
mModes = startActionMode(new AnActionModeOfEpicProportions());
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (int i = 1; i <= 6; i++) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setText("Tab " + i);
tab.setTabListener(this);
getSupportActionBar().addTab(tab);
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction transaction) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction transaction) {
mSelected.setText("Selected: " + tab.getText());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
}
private final class AnActionModeOfEpicProportions implements ActionMode.Callback {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
//Used to put dark icons on light action bar
boolean isLight = SampleList.THEME == R.style.Theme_Sherlock_Light;
menu.add("Save")
.setIcon(isLight ? R.drawable.ic_compose_inverse : R.drawable.ic_compose)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Search")
.setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.ic_search)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Refresh")
.setIcon(isLight ? R.drawable.ic_refresh_inverse : R.drawable.ic_refresh)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Save")
.setIcon(isLight ? R.drawable.ic_compose_inverse : R.drawable.ic_compose)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Search")
.setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.ic_search)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add("Refresh")
.setIcon(isLight ? R.drawable.ic_refresh_inverse : R.drawable.ic_refresh)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Toast.makeText(TabNavigation.this, "Got click: " + item, Toast.LENGTH_SHORT).show();
//mode.finish();
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
}
@Override
protected void onResume() {
super.onResume();
if(mModes!=null){
mModes = startActionMode(new AnActionModeOfEpicProportions());
}
}
}
In which mModes = startActionMode(new AnActionModeOfEpicProportions());
is the code which will provide the ActionBar. but how can I control the backKey press for this Actionbar class. Please suggest me.
Also I want to change the image provide on ActionBar. I am sorry but I have searched alot but didn't got the image click listener event in the code. Please help me.