Android方向更改会删除操作栏标签自定义视图

时间:2015-05-15 18:35:58

标签: android tabs android-actionbar android-actionbar-tabs

我已使用自定义视图创建了ActionBar个标签。我正在使用自定义视图,因为我想在选项卡中显示未读徽章计数。创建活动时,它们看起来很好。

enter image description here

当我更改设备的方向时,将从选项卡中删除所选选项卡的自定义视图。

enter image description here

当我使用平板电脑,只使用手机时,不会发生这种情况。有谁知道这可能导致什么?

以下是我使用的自定义视图

<?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);

更新 以下是创建活动时ActionBar的屏幕截图

enter image description here

当我改变方向时,这就是ActionBar的样子

enter image description here

现在,如果我在横向模式下创建活动,则ActionBar会正确加载

enter image description here

0 个答案:

没有答案
相关问题