0

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.

enter image description here

4

1 に答える 1

1

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.

startActionMode doesn't "provide the ActionBar" it starts the contextual action bar which is different from the standard ActionBar. You most likely don't need to observe the BACK button for the contextual action bar, but you do have a callback, because the BACK button will trigger the contextual action bar to be closed so onDestroyActionMode will be called. If you still want to look after the BACK button then implement a watch in the onBackPressed callback to see if it's called while the contextual action bar is currently showing.

Also I want to change the image provide on ActionBar.

For the standard ActionBar there are a lot of tutorials/samples/documentation on how to change its look. For the contextual action bar you also have options to change its appearance with a custom theme(for example, check this question).

I am sorry but I have searched alot but didn't got the image click listener event in the code

Doesn't make sense, explain better what you're looking for.

于 2013-03-26T11:51:45.267 に答える