Reputation: 39
I'm not sure if that is possible. I'm trying to do a screen with tabs and lists in every tabs (I've done that already) and I've done a custom ActionBar for the title and some icons on it, now, i want to change the text color of the tabs, I've solved the background color but i can't find anything related to the text color, here is a piece of my code .java and my manifest.xml
addMenu();
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
actionBar.show();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() | ActionBar.DISPLAY_SHOW_CUSTOM);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(
actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this)
);
}
the addMenu method (Only changes the Action Bar):
getSupportActionBar().setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.order_title, null);
TextView textView = (TextView) view.findViewById(R.id.mytext);
textView.setWidth(getWindow().getWindowManager().getDefaultDisplay().getWidth());
textView.setPadding(0, 0, 50, 0);
textView.setGravity(Gravity.CENTER);
Typeface segoeui = Typeface.createFromAsset(getAssets(),"fonts/segoeui.ttf");
textView.setTypeface(segoeui);
textView.setText("Some Text");
getSupportActionBar().setCustomView(view);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.arrow_left);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#afafaf")));
and my Manifest.xml:
<activity
android:name=".Activity1"
android:label="@string/title_activity1"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cleanpress.cleanpress.MainActivity" />
</activity>
This is how it looks: https://i.sstatic.net/0hRbv.png
As you can see, the screen that i'm working is related to another one (if that's relevant). I want to change just the text color of the Tabs (there are 3 tabs), anyone can help me please?
(I've already worked with HTML format and didn't work)
Upvotes: 0
Views: 431
Reputation: 23
try this in styles
<style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarTabTextStyle">@style/Widget.MyTabText</item>
</style>
<style name="Widget.MyTabText" parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/#your_color</item>
</style>
Upvotes: 0
Reputation: 1418
You should use android.support.design.widget.TabLayout to handle Tabs so you can adjust:
app:tabIndicatorColor="@color/colorAccent" //indicator color
app:tabSelectedTextColor="#EEE" // text color on selected tab
app:tabTextColor="#EEE" // text color on tab
you should also use android.support.v7.widget.Toolbar for ActionBar.
Exmaple:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:layout_alignParentTop="true"
android:text="@string/app_name"
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_below="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabIndicatorColor="@color/colorAccent"
app:tabSelectedTextColor="#EEE"
app:tabTextColor="#EEE" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tab_layout" />
</RelativeLayout>
In activity in onCreate
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
mAdapter = new YourPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mAdapter);
mTabLayout.setupWithViewPager(mPager);
Remember to add
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
in gradle dependencies
Upvotes: 1