如何从TabWidget中删除选定的选项卡指示器?

时间:2013-02-03 12:09:31

标签: android

以下是我要删除的内容:

enter image description here

如何更换显示当前显示哪个标签的指示符以及横跨整个tabwidget的蓝线?

指定:我想要指示选择哪个选项卡是:

    如果选项卡是SELECTED ,
  • tab_button_active.9.png应显示为背景 如果选项卡未选中,则
  • tab_button_inactive.9.png应显示为背景。

编辑:将tabStripEnabled设置为false无效。添加样式并将“@android:style / Widget.Holo.ActionBar”作为其父级也是不可能的,因为我的目标API级别7和ActionBar是在API级别11中实现的。

17 个答案:

答案 0 :(得分:32)

我还有另一个黑客。

    TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);

它和Eleojasmil的想法基本相同。

答案 1 :(得分:19)

这一行 app:tabIndicatorHeight="0dp" 在xml

中为我解决了这个问题
 <android.support.design.widget.TabLayout
        android:id="@+id/view_bottom_tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorHeight="0dp"             //this line
        app:tabGravity="fill"
        app:tabMode="fixed" />

答案 2 :(得分:14)

如果android:tabStripEnabled="false"不起作用,那么我也假设调用setStripEnabled(boolean stripEnabled)也没有效果。如果所有这些都是真的那么你的问题可能不在TabWidget中。

我建议您查看标签指示器。尝试这些修改。此代码取自具有选项卡的片段。

以下是创建标签指示符视图的代码。

    View indicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab,
(ViewGroup) mRoot.findViewById(android.R.id.tabs), false);

        TabSpec tabSpec = mTabHost.newTabSpec(tag);
        tabSpec.setIndicator(indicator);
        tabSpec.setContent(tabContentId);

您的标签指示器视图可能与此类似。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="@drawable/tabselector"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tab1icon"/>

</LinearLayout>

现在,重要的部分是LinearLayout中的android:background="@drawable/tabselector"。我看起来像这样。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/tab_unselected_light" />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_selected_light" />
    <!-- Focused states -->
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_focused_light" />
    <!-- Pressed state -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/tab_pressed_light" />
</selector>

此tabselector.xml是您与@drawable/tab_pressed_light@drawable/tab_button_active @drawable/tab_unselected_light

交换@drawable/tab_button_inactive的地方

请务必检查进入tabselector.xml的所有drawable是否都没有底部的蓝色条带。当我看到你的图像时,我可以看到沿着那个条带的小5px间隙这就是让我觉得条带不是来自你的TabWidget的想法。希望这会有所帮助。

答案 3 :(得分:14)

TabLayout: 只需使用app:tabIndicatorColor="@android:color/transparent"

<android.support.design.widget.TabLayout
        android:id="@+id/profile_album_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:tabBackground="@drawable/tab_background"
        app:tabIndicatorColor="@android:color/transparent"
        app:tabPadding="@dimen/common_margin" />

答案 4 :(得分:6)

有一行答案 你只需要将指标的颜色改为透明的

color.xml

 <color name="transparent2">#00000000</color>

并将此行添加到您的tabwidget

tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent2));

app:tabIndicatorColor="@color/transparent2"

答案 5 :(得分:5)

尝试将标签指示器高度设置为零:

- (FriendsCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FriendsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FriendsCollectionViewCell" forIndexPath:indexPath];
    // get the array that contains the items for your indexPath
    NSArray *items = [self itemArrayForIndexPath:indexPath];

    // case 2
    // if the section does not have any items then set up the
    // cell to display "No item" 
    if (items.count == 0) {
        [cell.lblFriendBand setText:@"No item"];
        [cell.lblFriendGenre setText:@""];
        [cell.lblFriendECScore setText:@""];
    }
    // case 1
    // setup the cell with your items
    else {
        // get you item here and set up the cell with your content
        // Item *item = items[indexPath.item];
        [cell.lblFriendBand setText:@"Band: White Mash  "];
        [cell.lblFriendGenre setText:@"Freestyle house,  House,  Freestyle music,"];
        [cell.lblFriendECScore setText:@"EC score: 79"];
    }

    return cell;
}

// return array for the corresponding indexPath
- (NSArray *)itemArrayForIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            return goldSectionItems;
        case 1:
            return silverSectionItems;
        case 2:
            return bronzeSectionItems;
        case 3:
            return greenSectionItems;
        case 4:
            return otherSectionItems;
        default:
            return nil;
    }
}

-(UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    FriendsFanLevelHeaderView *headerView = (FriendsFanLevelHeaderView *)[self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FanLevelHeader" forIndexPath:indexPath];

        switch (indexPath.section) {
            case 0:
                [headerView.lblFanLevelTitle setText:@"Gold"];
                break;
            case 1:
                [headerView.lblFanLevelTitle setText:@"Silver"];
                break;
            case 2:
                [headerView.lblFanLevelTitle setText:@"Bronze"];
                break;
            case 3:
                [headerView.lblFanLevelTitle setText:@"Green"];
                break;
            case 4:
                [headerView.lblFanLevelTitle setText:@"Other"];
                break;
            default:
                break;
        }

        return headerView;
}

答案 6 :(得分:2)

使用

    tabLayout.setSelectedTabIndicator(null);

这会将选定的可绘制指示器设置为空。

答案 7 :(得分:2)

将此添加到您的TabLayout XML

app:tabIndicator="@null"

答案 8 :(得分:1)

使用此app:tabIndicator="@null"

<com.google.android.material.tabs.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabIndicator="@null"
    app:tabMode="fixed" />

答案 9 :(得分:1)

android:tabStripEnabled="false"设置属性TabWidget

答案 10 :(得分:1)

这里使用了我的用法,因为tabIndicator.setSelectedTabIndicatorHeight(0);已废弃

使用tabIndicator.setSelectedTabIndicator(0);

答案 11 :(得分:1)

我找了很长时间才能删除丑陋的全息菜单栏 尝试了一切。意外地使用此代码的另一个原因,它感谢上帝删除它。

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {          
        tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); // unselected
        TextView tv = (TextView)tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
        tv.setTextColor(Color.parseColor("#ffffff"));
    }

来源:Android tabhost change text color style

答案 12 :(得分:0)

您只需在TabLayout上使用此方法即可隐藏Tab指示器。

I am trying to implement a simple websocket server using Play Framework.
I am receiving the client request in Controller and i can able to pass the request to Parent Actor(which takes actorRef as constructor arguement) which in turn passes the request to child actor.
Once the child actor processed the request, i am not able to send back the response to controller.

@Singleton
class RequestController @Inject()(cc: ControllerComponents)(implicit system: ActorSystem, mat: Materializer) extends AbstractController(cc) {
    def ws = WebSocket.accept[String, String] {req =>
    ActorFlow.actorRef { out =>
      ParentActor.props(out)
    }
  }
}
=======
object ParentActor {
  def props(out: ActorRef) = Props(new ParentActor(out))
}

class ParentActor(out : ActorRef) extends Actor {
implicit val actorSystem = ActorSystem("ab")
    override def receive: Receive = {
         case msg: String => 
            val childActor: ActorRef = actorSystem.actorOf(Props[ChildActor])
            childActor ! msg
         case msg: Response => out ! msg
    }
}
==================
case class Response(name:String, msg:String)
class ChildActor extends Actor{
implicit val actorSystem = ActorSystem("cd")
    override def receive: Receive = {
        case msg : String => 
        // Below statement is not working. I tried with sender() instead of self
        // which is also not working
        val parentActor = actorSystem.actorOf(Props(new ParentActor(self))) 
        parentActor ! Response("ABC",msg) 
    }
}

答案 13 :(得分:0)

使用tabLayout.setSelectedTabIndicator(0)

tabLayout.setSelectedTabIndicatorHeight(0)现在已被弃用,tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT)的性能也不好,因为它使用了透明性。

答案 14 :(得分:0)

为了获得最佳设置,app:tabIndicatorHeight="0dp"为我工作。

答案 15 :(得分:0)

我假设您正在使用ActionBarSherlock。使用TabWdiget的问题是,它不是ABS的一部分,因此它对于每个Android版本看起来都是“原生的”。对我来说,使用ABS进行标签导航的最佳方法是使用ViewPager和ViewPagerIndicator并为指标设置样式。缺点是,您的标签必须是片段。如果你需要你的标签作为活动,那么你应该看看HoloEveryhwhere的人是否设法添加了TabWidget。

答案 16 :(得分:-1)

tabHost.getTabWidget().setStripEnabled(false);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.tabcolor));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.tabcolor));

More info here