2

ActionBar

Hi guys, i'm trying to make ActionBar the same as in the image above (with this "wave"), where the red color can be changed at run time. I tried to use GradientDrawable (code below), but the gradient effect was not cool and it's not what i need.

        GradientDrawable gd = new GradientDrawable(
                GradientDrawable.Orientation.LEFT_RIGHT,
                new int[] {cor, Color.WHITE});
        gd.setCornerRadius(0f);

        actionBar.setBackgroundDrawable(gd);

Any idea?

2 Answers2

2

I'm not completly sure, but it can be done using custom drawable.xml something like this. Even, I think that you would have mix some drawables to get the image that you're posting.

An alternative is having the image in png or jpg that you want to set to actionbar and code this. Regards!

1

I created the red part of the image above at https://vectr.com (.svg). in Android Studio, i added a new shape_action_bar.xml (vector asset), from the created image.

in the activity I added the following code:

        Drawable drawable = getNavigationController().getResources().getDrawable(R.drawable.shape_action_bar);
        ColorFilter color = new PorterDuffColorFilter(selected_color, PorterDuff.Mode.SRC_ATOP );
        drawable.setColorFilter(color);

        actionBar.setBackgroundDrawable(drawable);

The shape will change color according to the desired color. Thankss