I can set ActionBar in onCreate
using below code.
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setBackgroundDrawable(getResources().getDrawable(
R.drawable.myDrawable1));
actionBar.setTitle("");
So what happens is that user clicks a button and that calls below method to show a listview. Here I change action bar's background to R.id.myDrawable2 successfully.
public void displayList() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent);
actionBar.setBackgroundDrawable(getResources().getDrawable(
R.drawable.myDrawable2));
// actionBar.setTitle("Some Nonempty text"); // If I uncomment this line then action bar background is correctly displayed.
// Display listview
.
.
.
}
Now, user clicks on an item of a listview and that starts another activity. Problem occurs when user come back to previous activity. When comes back, action bar background is gone. It is plain white.
And when user comes back user should be seeing that listview. So I call above method that displays listview and change action bar background to myDrawable2
. But here, action bar background is reset to plain white.
Note : If I set action bar title to some non-empty text then it is displayed with correct background.
I found a temporary workaround to reset text to "" immediately after setting it to some text. But this is not a proper solution.
Can anyone tell me what is wrong in setting background?
Edit : I noticed that this is a problem only when come back from next activity. If user is within same activity then I can change background without problem. e.g when user clicks cancel to hide list, I am able to change action bar background. Again able to do it when user clicks a button to display listview.