【问题标题】:Tabs: Unexplained view behind inflated tabs选项卡:膨胀选项卡背后的无法解释的视图
【发布时间】:2012-06-29 07:44:09
【问题描述】:

我有一个自定义选项卡活动,我在 SO 的大量帮助下将其组合在一起。但是,我遇到了几个问题,在这里我找不到答案。

首先,所有选项卡状态都来自我调整了颜色的 android apk 选项卡资源。未选中的标签九补丁图像显示在每个标签下方,我无法让它消失,有什么建议吗?

其次,当我第一次进入选项卡活动时,焦点选项卡的文本不会改变,但是当我按下选项卡,或者移动到另一个选项卡并返回时,文本会改变。如何让初始焦点文本显示为按下后显示的焦点文本?

这里有图片来说明我的意思;左侧初始加载,右侧按下,两个图像都显示未选择的选项卡图像显示在选项卡后面:

我尝试发布标签外观的图片,但我的代表还不够高。对不起!

这是我正在膨胀的选项卡布局 xml:

<?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="75dp"
    android:layout_weight="1"
    android:background="@drawable/custom_tab_selector"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/ivTabIicon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/tvTabTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

这是我的选择器 XML

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Active tab -->
    <item 
        android:drawable="@drawable/tab_selected" 
        android:state_focused="false" 
        android:state_pressed="false" 
        android:state_selected="true"/>

    <!-- Inactive tab -->
    <item 
        android:drawable="@drawable/tab_unselected"
        android:state_focused="false" 
        android:state_pressed="false" 
        android:state_selected="false"/>

    <!-- Pressed tab -->
    <item 
        android:drawable="@drawable/tab_press" 
        android:state_pressed="true"/>

    <!-- Selected tab (using d-pad) -->
    <item 
        android:drawable="@drawable/tab_focus" 
        android:state_focused="true" 
        android:state_pressed="false" 
        android:state_selected="true"/>

</selector>

这是我的活动 java 部分,它膨胀并显示每个选项卡

// Initialize a TabSpec for each tab and add it to the TabHost
// Team tab
View tabTeamIndicator = LayoutInflater.from(this).inflate(R.layout.tab_team_layout, getTabWidget(), false);
spec = tabHost.newTabSpec("teamTab");
title = (TextView) tabTeamIndicator.findViewById(R.id.tvTabTitle);
title.setText("Team Manager");
icon = (ImageView) tabTeamIndicator.findViewById(R.id.ivTabIicon);
icon.setImageResource(R.drawable.custom_teamtab_icon);

spec.setIndicator(tabTeamIndicator);
spec.setContent(intentTeam);
tabHost.addTab(spec);

非常感谢您的帮助!顺便说一句,我正在尝试的手机上的颜色看起来比在模拟器中的要好得多!!!

编辑:更改主题标题

【问题讨论】:

    标签: android tabs


    【解决方案1】:

    这里是愚蠢的错误。包含选项卡小部件的 xml 布局具有

    android:background="@drawable/custom_tab_selector"
    

    其中的属性导致选项卡的背景在后台第二次绘制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2012-08-14
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多