Action bar messed up after using setTitle

I am trying to set the actionBar header in action. I have 3 types of layout in one action. Each view layout displays a different state of the payment process. Now that I have set the title, at one point the background of the action bar is confused. I wonder why.

This does not happen if I comment on the next line.

onClick() { .... getActionBar().setTitle("Customer Payment"); .... 

In onCreate activity, I run the following command to customize the background of the action bar.

 private void setupActionBar() { Drawable backgroundColor; switch (getIntent().getIntExtra(God.HOME_SCREEN_OPERATION, God.INVALID_ID)) { case God.OPERATION_RECHARGE: getActionBar().setIcon(R.drawable.icon_mobile); backgroundColor = new ColorDrawable(getResources().getColor( R.color.RechargeBackgroundColor)); getActionBar().setBackgroundDrawable(backgroundColor); mobileServiceSummary.setVisibility(View.VISIBLE); serviceInfoLayout.setBackground(backgroundColor); serviceInfoIcon.setImageResource(R.drawable.icon_mobile); break; case God.OPERATION_FACILITY: getActionBar().setIcon(R.drawable.icon_facility); backgroundColor = new ColorDrawable(getResources().getColor( R.color.ToiletBackgroundColor)); getActionBar().setBackgroundDrawable(backgroundColor); facilityServiceSummary.setVisibility(View.VISIBLE); serviceInfoLayout.setBackground(backgroundColor); serviceInfoIcon.setImageResource(R.drawable.icon_facility); break; case God.OPERATION_DTH: getActionBar().setIcon(R.drawable.icon_dth); backgroundColor = new ColorDrawable(getResources().getColor( R.color.DthBackgroundColor)); getActionBar().setBackgroundDrawable(backgroundColor); dthServiceSummary.setVisibility(View.VISIBLE); serviceInfoLayout.setBackground(backgroundColor); serviceInfoIcon.setImageResource(R.drawable.icon_dth); break; // case R.id.mseb_payment: // getActionBar().setIcon(R.drawable.icon_mseb); // msebServiceSummary.setVisibility(View.VISIBLE) ; // break; default: break; } } 

Another code.

 private void enableCustomerPayment() { getActionBar().setTitle("Customer Payment"); getActionBar().setSubtitle( "Pincode of customer needed for payment permission."); getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); getActionBar().setDisplayShowCustomEnabled(false) ; getActionBar().setDisplayUseLogoEnabled(false) ; findViewById(R.id.next_button).setVisibility(View.GONE); findViewById(R.id.payment_button).setVisibility(View.VISIBLE); findViewById(R.id.done_button).setVisibility(View.GONE); operatorLockLayout.setVisibility(View.GONE); customerLoginAndConfirmationLayout.setVisibility(View.VISIBLE); customerPaymentLayout.setVisibility(View.GONE); customerConfirmLayout.setVisibility(View.VISIBLE); // customerConfirmSpaceLayout.setVisibility(View.VISIBLE); } private void enablePaymentConfirmation() { getActionBar().setTitle("Payment Confirmation"); getActionBar().setSubtitle("Thankyou for your payment."); setupActionBar(); getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); findViewById(R.id.next_button).setVisibility(View.GONE); findViewById(R.id.payment_button).setVisibility(View.GONE); findViewById(R.id.done_button).setVisibility(View.VISIBLE); operatorLockLayout.setVisibility(View.GONE); customerLoginAndConfirmationLayout.setVisibility(View.VISIBLE); customerPaymentLayout.setVisibility(View.VISIBLE); customerConfirmLayout.setVisibility(View.GONE); // customerConfirmSpaceLayout.setVisibility(View.GONE); } 

In styles.xml, the color is configured as follows. And the colors work fine.

 <color name="NewWalletBackgroundColor">#FFD54E</color> <color name="BalanceBackgroundColor">#FFD54E</color> <color name="DepositBackgroundColor">#FFD54E</color> <color name="MsebBackgroundColor">#E57272</color> <color name="RechargeBackgroundColor">#81C784</color> <color name="DthBackgroundColor">#AB6BAC</color> <color name="ToiletBackgroundColor">#56C0ED</color> 

The action bar is messed up

enter image description here

Here the background of the Action Bar is completely blue. This is what I expect.

enter image description here

Edit

There seems to be a problem with height, it starts at 96, and when its spoiled height is 0.

How can I fix it now?

+5
source share
2 answers

In my opinion, the action bar by default expects the navigation box icon icon to the right of the action bar. I think there is a transparent button in the space you are talking about. Even if you install the box for this action or not, it will be there if you use standard methods to install the action bar. First try these steps.

  setDrawerIndicatorEnabled(false). actionBar.setDisplayHomeAsUpEnabled(false) actionBar.setHomeButtonEnabled(false); 

If this does not work, go to the custom action bar.

Do something like that. Instead of using the default action bar, why don't you try setting a custom view (regular TextView, where its width is set according to the parent).

  this.getActionBar().setDisplayShowCustomEnabled(true); this.getActionBar().setDisplayShowTitleEnabled(false); LayoutInflater inflator = LayoutInflater.from(this); View v = inflator.inflate(R.layout.titleview, null); //if you need to customize anything else about the text, do it here. ((TextView)v.findViewById(R.id.title)).setText(this.getTitle()); //assign the view to the actionbar this.getActionBar().setCustomView(v); 
0
source

I come from your question that enablePaymentConfirmation works with the code getActionBar().setTitle("Customer Payment"); present when it is commented out. If he also plays, then I will need to change my answer.

Not seeing that your xml makes this a bit more guessing work, but I see that I suggest the following.
1. Call setupActionBar() from you OnCreate in your activity. Thus, it is configured for the duration of your activity. If you do not call it in OnCreate, if you call enableCustomerPayment() before enablePaymentConfirmation() , the action bar setting will not be called.

2. If you have not specified the following code changes, they can enter your setupActionbar:

  getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); 

3. These are two changes to the ActionBar between the two methods that you show:

 getActionBar().setDisplayShowCustomEnabled(false) ; getActionBar().setDisplayUseLogoEnabled(false) ; 

4. I am not sure why you are setting setDisplayShowCustomEnabled to your enableCustomerPayment() . I do not see that you are using customView. - If not, it can also go into your setup. - Otherwise, you will need to call it in all your methods with changes. - If you use a custom view for your action screen in some places and not others, it will affect how it is displayed. In particular, if you do not control bool changes.

5. The same goes for the logo; I don’t see where you use it. Therefore, I would put it in the settings. If you use it for others and you don’t have xml configured correctly, that’s probably why there is a difference in background color.

Hope this helps. Feel free to post more info, xml will be fine.

0
source

All Articles