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):
<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:
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
I'll suggest to add a style to your 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:
<style name="your_style">
<item name="android:textColor">#00FF00</item>
</style>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.