[英]Change text color of tabs
i'm trying to make scrollable tabs. 我正在尝试制作可滚动的标签。 I got it all working but i don't know how to change the text color of the individual tabs, this is my code... XML(MainActivity):
我可以正常工作,但是我不知道如何更改各个选项卡的文本颜色,这是我的代码... XML(MainActivity):
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/pager"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:layout_gravity="top"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:background="#000000"
android:focusableInTouchMode="true"/>
</android.support.v4.view.ViewPager>
MainActivity.java: MainActivity.java:
public class MainActivity extends FragmentActivity {
ViewPager viewPager = null;
@Override
protected void onCreate(Bundle savedInstanceStats) {
super.onCreate(savedInstanceStats);
setContentView(R.layout.homescreen);
viewPager = (ViewPager) findViewById(R.id.pager);
FragmentManager fragmentManager = getSupportFragmentManager();
viewPager.setAdapter(new MyAdapter(fragmentManager));
}
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
if(position == 0) {
fragment = new FragmentDominik();
} else if(position == 1) {
fragment = new FragmentTobias();
} else if(position == 2) {
fragment = new FragmentTom();
} else if(position == 3) {
fragment = new FragmentNikolas();
}
return fragment;
}
@Override
public int getCount() {
return 4;
}
public CharSequence getPageTitle(int position) {
String title = new String();
if(position == 0) {
return "Dominik";
} else if(position == 1) {
return "Tobias";
} else if(position == 2) {
return "Tom";
} else if(position == 3) {
return "Nikolas";
}
return null;
}
}
so the default text color is black, but i want the text to be white and (i already got that)the background to be black, here's a picture: 所以默认的文本颜色是黑色,但是我希望文本是白色,(我已经知道)背景是黑色,这是一张图片:
I'm kind of new to xml and java and I just used a tutorial online to make this scrollable tabs, so any help is appreciated :) thanks 我是xml和java的新手,我只是在线使用了一个教程来制作此可滚动的标签,因此可以提供任何帮助:)谢谢
I'll suggest to add a style to your PagerTitleStrip: 我建议为您的PagerTitleStrip添加样式:
<android.support.v4.view.PagerTitleStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:layout_gravity="top"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:background="#000000"
android:focusableInTouchMode="true"
style="@style/your_style"
/>
And then in your styles.xml: 然后在您的styles.xml中:
<style name="your_style">
<item name="android:textColor">#00FF00</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.