johannilsson / android-actionbar

DEPRECATED Android Action Bar Implementation
1.31k stars 564 forks source link

Feature: Change action bar icon #5

Closed caojunvincent closed 13 years ago

caojunvincent commented 13 years ago

sometime i need change the icon of exsit actionbar, like change privacy.

johannilsson commented 13 years ago

Think it should be possible to do by implementing Action on a custom action like the ToastAction in the README file.

I've been thinking of applying this patch that will pass a View to the method performAction from there it should also be possible to change the icon direct on the View object. Not sure if that's what your're looking for though?

caojunvincent commented 13 years ago

this "patch" is exactly what i want, thanks for your code

johannilsson commented 13 years ago

Changed to pass View to performAction

As suggested by rpdillon in his fork[1].

Note, this change breaks the api for performAction, if you have custom actions they need to be migrated to the new interface. This is done by adding View as an argument to performAction. The ToastAction in the example project now looks like;

private class ToastAction implements Action {

    @Override
    public int getDrawable() {
        return R.drawable.ic_title_export_default;
    }

    @Override
    public void performAction(View view) {
        Toast.makeText(OtherActivity.this,
                "Example action", Toast.LENGTH_SHORT).show();
    }

}

This also closed by d7b2115583c5b12e0409d97fc5ec78442e5fa5c1

[1] https://github.com/rpdillon/android-actionbar/commit/27da74326341b5ad7a3f1dbfd7ea091c36aae9be