Since the ActionBar.TabListener is now deprecated i've followed this tutorial for set up the Material Design Sliding Tabs:
http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html
It works but i'm trying to remove the line+shadow below the action bar with no success.. Even setting the getSupportActionBar().setElevation(0); as suggested in other threads.
I know that if i set the custom style of the activity to @style/Theme.AppCompat instead of @style/Theme.AppCompat.Light (the actual config) the line+shadow disappear, but the options menu and the others activity that share this style become dark.. and i don't want it.
So i'm trying to find a way for remove the line+shadow and keep the main style as "Light".
MainActivity (OnCreate)
public class MainActivity extends AppCompatActivity {
// Declaring Your View and Variables
Toolbar toolbar;
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;
CharSequence Titles[]={"1","2","3","4"};
int Numboftabs =4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setElevation(0);
setContentView(R.layout.activity_main);
//
// Creating The Toolbar and setting it as the Toolbar for the activity
toolbar = (Toolbar) findViewById(R.id.tool_bar);
//setSupportActionBar(toolbar);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.darkgreen);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_height="10dp"
android:layout_width="match_parent"
android:layout_gravity="right" />
<com.myapp.library.sliding_tab.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:theme="@style/Theme.AppCompat"
android:background="@color/orange"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:textColor="@color/black"
android:background="@color/white">
</android.support.v4.view.ViewPager>
</LinearLayout>
tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/orange"
android:elevation="0dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Light"
xmlns:android="http://schemas.android.com/apk/res/android" />
styles.xml
<resources>
<style name="MyCustomTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
<item name="android:actionBarTabBarStyle">@style/MyActionBarTabTheme</item>
<item name="actionBarStyle">@style/MyActionBarTheme</item>
<item name="actionBarTabBarStyle">@style/MyActionBarTabTheme</item>
</style>
<style name="MyActionBarTheme" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/orange</item>
<item name="background">@color/orange</item>
</style>
<style name="MyActionBarTabTheme" parent="@style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">@color/orange</item>
<item name="background">@color/orange</item>
</style>
</resources>
manifest (only the mainactivity)
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/MyCustomTheme">
</activity>