ActionBar
カスタム ビューでタブを作成しました。タブ内に未読のバッジ数を表示したいので、カスタム ビューを使用しています。アクティビティが作成されると、問題なく表示されます。
デバイスの向きを変更すると、選択したタブのカスタム ビューがタブから削除されます。
これは、タブレットを使用しているときは発生せず、電話のみです。誰がこれを引き起こしているのか知っていますか?
これが私が使用しているカスタムビューです
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/ivTabIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_centerInParent="true"
android:src="@drawable/ic_action_messages" />
<TextView
android:id="@+id/tvBadgeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/ivTabIcon"
android:layout_alignTop="@id/ivTabIcon"
android:layout_marginRight="0dp"
android:layout_marginTop="3dp"
android:background="@drawable/background_message_notification"
android:gravity="center"
android:minWidth="17sp"
android:paddingBottom="1dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="@null"
android:textColor="@color/white"
android:textSize="12sp" />
</RelativeLayout>
カスタムビューを膨らませるときのコードは次のとおりです
RelativeLayout messageView = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.tab_message, null);
ImageView messageIcon = (ImageView) inboxView.findViewById(R.id.ivTabIcon);
messageIcon.setImageResource(R.drawable.ic_action_messages);
TextView tabBadgeInbox = (TextView) inboxView.findViewById(R.id.tvBadgeCount);
actionBar.newTab().setCustomView(messageView);
UPDATE アクティビティが作成されたときのActionBarのスクリーンショットは次のとおりです
ここで向きを変えると、ActionBar は次のようになります。
ランドスケープ モードでアクティビティを作成すると、ActionBar が正しく読み込まれます