-1

The overflow dots with my activity remain white hence don't change colour when using the code below. Does anyone know how to solve this issue?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wc_bank);

    ActionBar actionBar = getSupportActionBar();

    getSupportActionBar().setElevation(0);

    //change background colour of action bar
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#66CCCC")));
    //change text colour of action bar
    actionBar.setTitle(Html.fromHtml("<font color='#000099'>Hello World</font>"));

    //change colour of action bar back arrow
    final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    upArrow.setColorFilter(getResources().getColor(R.color.blue), PorterDuff.Mode.SRC_ATOP);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);

    //enable and show action bar back arrow
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    final Drawable overflowDots = getResources().getDrawable(R.drawable.abc_ic_menu_moreoverflow_mtrl_alpha);
    overflowDots.setColorFilter(getResources().getColor(R.color.piccadilly), PorterDuff.Mode.SRC_ATOP);
}
wbk727
  • 8,017
  • 12
  • 61
  • 125

1 Answers1

1

The problem is that you aren't doing anything with your tinted Drawable. You get an instance of your abc_ic_menu_moreoverflow_mtrl_alpha icon and you set a ColorFilter on it, but then you aren't actually using that Drawable anywhere.

Unfortunately there also isn't a good way to set a Drawable object as your overflow menu icon. If you insist on doing this in your Java code, you can use this answer to accomplish that, but it is pretty hacky.

The preferred way is to use a custom style and the android:actionOverflowButtonStyle theme attribute to reference a Drawable resource. This means that if you use this option, you need to create a new asset with the correct color and include that in your drawable resource folders. Your theme will end up looking something like this:

<style name="Your.Theme" parent="@android:style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionOverflowButtonStyle">@style/Your.Theme.OverflowStyle</item>
</style>

<style name="Your.Theme.OverflowStyle" parent="@android:style/Widget.AppCompat.ActionButton.Overflow">
    <item name="android:src">@drawable/your_overflow_icon</item>
</style>
Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120