您好,我正在使用带 View 寻呼机的选项卡布局,在 FragmentPagerAdapter 中,我正在使用自定义布局根据位置定义每个 View 。现在我想实现这个效果,如图所示(选择的那个比其他的更白) .如何突出显示此图像中具有不同阴影的自定义 View 。我的所有选项卡都是相同的,无论是选中还是取消选中。 早些时候我使用默认文本并且它正在工作但现在我正在使用带有图像和文本的自定义 View 并且我不知道如何将它应用到自定义 View 。
最佳答案
这个有效:
...onCreate(){
...
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override public void onTabChanged(String arg0) {
setTabColor(tabHost);
}
});
setTabColor(tabHost);
...
} //Change The Backgournd Color of Tabs
public void
setTabColor(TabHost tabhost) {
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected
if(tabhost.getCurrentTab()==0) {
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab())
.setBackgroundColor(COLOR_RED); //1st tab selected
}else{ tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected
}
编辑
这是覆盖文本样式和选定文本颜色的代码 fragment
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">@style/MyCustomTabText</item>
<item name="tabSelectedTextColor">@color/tab_text_act</item>
</style>
<style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/tab_text</item>
</style>
这是布局的代码 fragment
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MyCustomTabLayout" />
关于java - 突出显示选项卡 View 寻呼机android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35757650/