我是android的新手..我目前有关于如何更改标签文字颜色的问题?我没有使用tabHost,还有没有tabhost的另一种方法吗?
我按照本教程创建一个 Android Tab Layout with Swipeable Views
public class UserLogin extends FragmentActivity implements ActionBar.TabListener {
private SignIn signIn;
private ViewPager viewPager;
private TabPagerAdapter tabAdapter;
private ActionBar actionBar;
private String[] tabs = { "LOG IN", "SIGN UP"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_login);
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
tabAdapter = new TabPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabAdapter);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar = getActionBar();
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
我应该修改什么才能将文字颜色改为蓝色..
答案 0 :(得分:0)
选项卡基本上是操作栏,因此如果更改操作栏文本颜色,选项卡文本颜色应该更改。这是更改操作栏文本颜色的一种方法。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
</resources>
答案 1 :(得分:0)
在xml文件中尝试以下代码,以获取活动和非活动文本颜色更改
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
app:pstsTabSwitch="true"
app:pstsActivateTextColor="#FF666666"
app:pstsDeactivateTextColor="#FFCCCCCC" />