3
我有包括圖像和一個TextView的菜單項:菜單項呈現錯了4.0.3
顯示以及在4.3,但在4.0/4.1它沒有(與ActionBarCompat同樣的問題):
menu_action_cart.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/actionCart"
android:actionLayout="@layout/menu_cart_button"
android:title="@string/action_cart"
android:showAsAction="always"/>
</menu>
menu_cart_button.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<ImageView
android:id="@+id/actionIcon"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:clickable="true"
android:src="@drawable/menu_bag" />
<TextView
android:id="@+id/actionbar_notification_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:paddingTop="10dp"
android:textColor="@color/red"/>
</RelativeLayout>
的Java:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.menu_action_cart, menu);
MenuItem menuItem = menu.findItem(R.id.actionCart);
View badgeLayout = menuItem.getActionView();
TextView textView = (TextView) badgeLayout.findViewById(R.id.actionbar_notification_text);
ImageView imageView = (ImageView) badgeLayout.findViewById(R.id.actionIcon);
textView.setText("1");
imageView.setEnabled(true);
textView.setTextColor(getResources().getColor(R.color.orogo_red));
imageView.setImageResource(R.drawable.menu_bag);
return super.onCreateOptionsMenu(menu);
}
如果我真的要這樣做,我會哭泣! :) – Mika