Android 如何从TabWidget中删除选定的选项卡指示器?
以下是我想删除的内容: 如何替换显示当前显示哪个选项卡以及跨越整个tabwidget的蓝线的指示器 要指定:我只想指示选择了哪个选项卡,请执行以下操作:Android 如何从TabWidget中删除选定的选项卡指示器?,android,Android,以下是我想删除的内容: 如何替换显示当前显示哪个选项卡以及跨越整个tabwidget的蓝线的指示器 要指定:我只想指示选择了哪个选项卡,请执行以下操作: 如果选择了选项卡,则tab_button_active.9.png应显示为背景 如果未选择选项卡,则tab_button_inactive.9.png应显示为背景 编辑:将tabStripEnabled设置为false无效。向其添加样式并将“@android:style/Widget.Holo.ActionBar”作为其父级也是不可能的,
- 如果选择了选项卡,则tab_button_active.9.png应显示为背景
- 如果未选择选项卡,则tab_button_inactive.9.png应显示为背景李>
编辑:将tabStripEnabled设置为false无效。向其添加样式并将“@android:style/Widget.Holo.ActionBar”作为其父级也是不可能的,因为我的目标是API级别7,而ActionBar是在API级别11中实现的。为您的
TabWidget
设置属性android:tabStripEnabled=“false”
。使用TabWdiget的问题是,它不是ABS的一部分,因此对于每个Android版本,它看起来都是“本地的”。对我来说,使用ABS进行选项卡导航的最佳方法是使用ViewPager和ViewPagerIndicator并设置指示器的样式。缺点是,您的标签必须是碎片。如果你需要你的标签成为活动,那么你应该看看HoloEveryWhere的人是否成功添加了TabWidget。如果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>
此tabselector.xml是您将@drawable/tab_pressed_灯
与激活的@drawable/tab_按钮
和@drawable/tab_unselected_灯
交换的位置
请确保检查进入tabselector.xml的所有绘图表底部没有蓝色条纹。当我看到你的图像时,我可以看到沿着条带有5px的小间隙,这让我想到条带不是来自你的TabWidget。希望这能有所帮助。我花了很长时间才删除丑陋的全息菜单栏 什么都试过了。出于另一个原因意外使用了此代码,感谢上帝将其删除
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"));
}
for(int i=0;i
来源:对此只有一行答案 您只需将指示器的颜色更改为透明 color.xml
<color name="transparent2">#00000000</color>
或
我还有一个黑客
TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
tabLayout.setSelectedTabIndicatorHeight(0);
这与Eleojasmil的想法基本相同。对于
表格布局
:
只需使用app:tabIndicatorColor=“@android:color/transparent”
尝试将选项卡指示器高度设置为零:
tabLayout.setSelectedTabIndicatorHeight(0);
这行代码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" />
将此添加到您的
表格布局XML
:
app:tabIndicator="@null"
您只需在tablayout上使用此方法来隐藏选项卡指示器
tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT);
使用
tabLayout.setSelectedTabIndicator(0)
tabLayout.setSelectedTabidIndicator高度(0)
现在已被弃用,而tabLayout.setSelectedTabidIndicator颜色(Color.TRANSPARENT)
将无法执行,因为它使用透明度。使用
tabLayout.setSelectedTabIndicator(null);
这会将所选的可绘制指示器设置为空。这里是我使用的,因为
选项卡indicator.setSelectedTabIndicator高度(0)代码>已取消加密
使用tabIndicator.setSelectedTabIndicator(0)代码>为了获得最佳设置,app:tabIndicatorHeight=“0dp”对我很有效。使用此app:tabIndicator=“@null”
在TabWidget中设置android:tabstripeenabled=“false”没有效果。哦……太糟糕了。。请尝试android:tabstripeenabled=“false”android:alpha=“0”
,这样可以使整个tabwidget透明,然后我需要自己尝试一下,然后再与您联系。很抱歉让你失望,我没有用ABS。简单的v4支持库。不管怎样,我的方法都不需要ABS。我提到它是因为它与ABS配合使用。我想你错过了为OPs问题提供解决方案的部分。你可以自定义actionbar的所有内容。有一个很好的教程和一个类似的问题,你是否尝试过这个stackoverflow帖子:重复我的答案很好:)现在不推荐透明颜色:android.R.color.transparentandroid:tabStripEnabled=“false”对我不可用。相反,我不得不使用app:tabIndicatorHeight=“0dp”现在java说tabLayout.setSelectedTabidIndicatorHeight(0)
方法已弃用。
<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" />
tabHost.getTabWidget().setStripEnabled(false);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.tabcolor));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.tabcolor));
app:tabIndicator="@null"
tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT);
tabLayout.setSelectedTabIndicator(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" />