Actionbar background is not being changed

前端 未结 2 1904
Happy的楠姐
Happy的楠姐 2020-12-11 09:48

I have tried with the following code to change the background of the actionbar. It works with 4.3 but not below 4.3. With the following code, null background is being set i

2条回答
  •  死守一世寂寞
    2020-12-11 10:10

    The only think that you can do is to call invalidateOptionsMenu () after setting background for actionbar..

     public void onStartClicked(View v) {
            int Min = 0;
            int Max = 2;
    
            //Random number generator between 0 and 2 inclusive
            int pos = Min + (int) (Math.random() * ((Max - Min) + 1));
    
            if (pos == 0) {
                getActionBar().setBackgroundDrawable(
                        getResources().getDrawable(R.drawable.header));
            } else if (pos == 1) {
                getActionBar().setBackgroundDrawable(
                        getResources().getDrawable(R.drawable.inbox_header));
    
            } else if (pos == 2) {
                getActionBar().setBackgroundDrawable(
                        getResources().getDrawable(R.drawable.outbox_header));
    
            }
           invalidateOptionsMenu();
        }
    

提交回复
热议问题