【发布时间】:2015-08-15 06:28:00
【问题描述】:
我正在尝试在活动中设置 actionBar 的标题。我在一项活动中有 3 个布局视图。每个视图布局显示付款过程的不同状态。现在我设置了标题,在某个阶段操作栏背景变得混乱。我想知道为什么。
如果我注释掉以下行,则不会发生这种情况。
onClick() {
....
getActionBar().setTitle("Customer Payment");
....
在活动的 onCreate 中,我运行以下命令来设置操作栏背景。
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;
}
}
更多代码..
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);
}
在styles.xml 中,颜色是这样设置的。而且颜色很好用。
<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>
操作栏搞砸了
这里,Action Bar 背景是完全蓝色的。这是我所期望的。
编辑
似乎高度有问题,它以96开始,当它搞砸时高度为0。
我现在该如何解决这个问题?
【问题讨论】:
-
操作栏的更多代码
-
你想要的预期输出是什么?能否请您添加最终图像。这样我就可以了解一下,然后我将添加我之前使用的自定义代码。
-
我希望整个操作栏都有背景颜色。我想知道为什么会有这个差距。
-
在另一个视图中有你想要的蓝色操作栏吗?
-
是的..我需要它全蓝色..