I'm trying to use a custom view as the icon next to the up button. I searched for a solution online and read something about using a drawing cache and tried implementing it in my code but no icon is showing.
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.scheme_dark_blue)));
bar.setTitle(i.getStringExtra("schoolDay"));
CalendarIcon icon = (CalendarIcon) getLayoutInflater().inflate(R.layout.icon_calendar, null);
icon.setDrawingCacheEnabled(true);
day = Integer.parseInt(i.getStringExtra("date"));
icon.setData(day + "");
icon.buildDrawingCache();
bar.setIcon(new BitmapDrawable(getResources(), icon.getDrawingCache()));
bar.setDisplayHomeAsUpEnabled(true);
Thanks for any help :)
Your code is probably not working because the view does not have a size yet. I also suggest you don't use the drawing cache but instead draw the view on a canvas.
I have written a little example where the view is given a size when it doesn't have one yet. You may want to tune to code a bit to fit your needs.
Example:
Usage:
Result: