Skip to content

Commit 581e4fc

Browse files
committed
Adjusted slidingtablayout and added toolbar
1 parent 760b68c commit 581e4fc

File tree

9 files changed

+84
-43
lines changed

9 files changed

+84
-43
lines changed

app/src/main/java/com/saulmm/material/slidingtabs/MainActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.app.Activity;
2020
import android.app.FragmentTransaction;
2121
import android.os.Bundle;
22+
import android.support.v7.app.ActionBarActivity;
23+
import android.support.v7.widget.Toolbar;
2224
import com.saulmm.material.R;
2325

2426
/**
@@ -28,7 +30,7 @@
2830
* For devices with displays with a width of 720dp or greater, the sample log is always visible,
2931
* on other devices it's visibility is controlled by an item on the Action Bar.
3032
*/
31-
public class MainActivity extends Activity {
33+
public class MainActivity extends ActionBarActivity {
3234

3335
public static final String TAG = "MainActivity";
3436

@@ -46,5 +48,11 @@ protected void onCreate(Bundle savedInstanceState) {
4648
transaction.replace(R.id.sample_content_fragment, fragment);
4749
transaction.commit();
4850
}
51+
52+
// Configure toolbar
53+
Toolbar mainToolbar = (Toolbar) findViewById(R.id.toolbar);
54+
setSupportActionBar(mainToolbar);
55+
getSupportActionBar().setTitle("Sliding");
56+
4957
}
5058
}

app/src/main/java/com/saulmm/material/slidingtabs/SlidingTabsBasicFragment.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.view.LayoutInflater;
2626
import android.view.View;
2727
import android.view.ViewGroup;
28+
import android.widget.Button;
2829
import android.widget.TextView;
2930

3031
import com.saulmm.material.R;
@@ -90,13 +91,14 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
9091
* {@link SlidingTabLayout}.
9192
*/
9293
class SamplePagerAdapter extends PagerAdapter {
94+
final String [] TITLES = {"CATEGORIES", "HOME", "TOP SELLING", "TOP GAMES", "TOP GROSSING"};
9395

9496
/**
9597
* @return the number of pages to display
9698
*/
9799
@Override
98100
public int getCount() {
99-
return 10;
101+
return 5;
100102
}
101103

102104
/**
@@ -118,7 +120,7 @@ public boolean isViewFromObject(View view, Object o) {
118120
*/
119121
@Override
120122
public CharSequence getPageTitle(int position) {
121-
return "Item " + (position + 1);
123+
return TITLES[position];
122124
}
123125
// END_INCLUDE (pageradapter_getpagetitle)
124126

@@ -132,13 +134,10 @@ public Object instantiateItem(ViewGroup container, int position) {
132134
View view = getActivity().getLayoutInflater().inflate(R.layout.pager_item,
133135
container, false);
134136
// Add the newly created View to the ViewPager
135-
container.addView(view);
136137

137-
// Retrieve a TextView from the inflated View, and update it's text
138-
TextView title = (TextView) view.findViewById(R.id.item_title);
139-
title.setText(String.valueOf(position + 1));
140138

141-
Log.i(LOG_TAG, "instantiateItem() [position: " + position + "]");
139+
container.addView(view);
140+
142141

143142
// Return the View
144143
return view;

app/src/main/java/com/saulmm/material/slidingtabs/views/SlidingTabLayout.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import android.widget.HorizontalScrollView;
3030
import android.widget.TextView;
3131

32+
import com.saulmm.material.R;
33+
3234
/**
3335
* To be used with ViewPager to provide a tab indicator component which give constant feedback as to
3436
* the user's scroll progress.
@@ -67,7 +69,7 @@ public interface TabColorizer {
6769

6870
private static final int TITLE_OFFSET_DIPS = 24;
6971
private static final int TAB_VIEW_PADDING_DIPS = 16;
70-
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
72+
private static final int TAB_VIEW_TEXT_SIZE_SP = 14;
7173

7274
private int mTitleOffset;
7375

@@ -173,6 +175,7 @@ protected TextView createDefaultTabView(Context context) {
173175
textView.setGravity(Gravity.CENTER);
174176
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
175177
textView.setTypeface(Typeface.DEFAULT_BOLD);
178+
textView.setTextAppearance(context, R.style.SlidingTextViewStyle);
176179

177180
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
178181
// If we're running on Honeycomb or newer, then we can use the Theme's

app/src/main/java/com/saulmm/material/slidingtabs/views/SlidingTabStrip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SlidingTabStrip extends LinearLayout {
3030

3131
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 2;
3232
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
33-
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 2;
33+
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
3434
private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
3535

3636
private static final int DEFAULT_DIVIDER_THICKNESS_DIPS = 1;

app/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
android:layout_height="match_parent"
66
android:id="@+id/sample_main_layout">
77

8+
<android.support.v7.widget.Toolbar
9+
android:id="@+id/toolbar"
10+
android:layout_height="wrap_content"
11+
android:layout_width="match_parent"
12+
android:background="?android:colorPrimary"
13+
android:minHeight="?attr/actionBarSize"/>
14+
815
<FrameLayout
916
android:id="@+id/sample_content_fragment"
1017
android:layout_weight="2"
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
5-
android:orientation="vertical">
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#FFF"
6+
android:orientation="vertical">
67

7-
<android.support.v7.widget.Toolbar
8-
android:id="@+id/toolbar"
9-
android:layout_height="wrap_content"
8+
<com.saulmm.material.slidingtabs.views.SlidingTabLayout
9+
android:id="@+id/sliding_tabs"
1010
android:layout_width="match_parent"
11-
android:background="?android:colorPrimary"
12-
android:minHeight="?attr/actionBarSize"/>
11+
android:layout_height="wrap_content"
12+
android:elevation="10dp"/>
1313

14-
<com.saulmm.material.slidingtabs.views.SlidingTabLayout
15-
android:id="@+id/sliding_tabs"
16-
android:layout_width="match_parent"
17-
android:layout_height="wrap_content" />
14+
<View
15+
android:layout_width="match_parent"
16+
android:layout_height="1dp"
17+
android:background="@color/theme_default_primary"
18+
android:elevation="10dp"/>
1819

1920
<android.support.v4.view.ViewPager
20-
android:id="@+id/viewpager"
21-
android:layout_width="match_parent"
22-
android:layout_height="0px"
23-
android:layout_weight="1"
24-
android:background="@android:color/white"/>
21+
android:id="@+id/viewpager"
22+
android:layout_width="match_parent"
23+
android:layout_height="0px"
24+
android:layout_weight="1"
25+
android:layout_marginBottom="10dp"
26+
android:background="@android:color/white"/>
2527

2628
</LinearLayout>

app/src/main/res/layout/pager_item.xml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,31 @@
66
android:orientation="vertical"
77
android:gravity="center">
88

9-
<TextView
10-
android:id="@+id/item_subtitle"
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:textAppearance="?android:attr/textAppearanceLarge"
14-
android:text="Page:"/>
15-
16-
<TextView
17-
android:id="@+id/item_title"
18-
android:layout_width="wrap_content"
19-
android:layout_height="wrap_content"
20-
android:textSize="80sp" />
9+
<LinearLayout
10+
xmlns:android="http://schemas.android.com/apk/res/android"
11+
android:orientation="vertical"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:id="@+id/sample_main_layout">
15+
16+
17+
<FrameLayout
18+
android:id="@+id/sample_content_fragment"
19+
android:layout_weight="2"
20+
android:layout_width="match_parent"
21+
android:layout_height="0px">
22+
23+
<LinearLayout
24+
android:layout_width="150dp"
25+
android:layout_height="150dp"
26+
android:layout_gravity="center"
27+
android:background="#FFF000"
28+
android:id="@+id/b1"
29+
android:elevation="10dp"/>
30+
31+
</FrameLayout>
32+
33+
</LinearLayout>
34+
2135

2236
</LinearLayout>
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4-
<style name="AppTheme" parent="Theme.AppCompat">
4+
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
55

6+
<!-- android theme colors -->
67
<item name="android:colorPrimary">@color/theme_default_primary</item>
78
<item name="android:colorPrimaryDark">@color/theme_default_primary_dark</item>
8-
<item name="android:statusBarColor">@color/theme_default_primary</item>
9+
<item name="android:statusBarColor">@color/theme_default_primary_dark</item>
910
<item name="android:colorAccent">@color/accent</item>
11+
12+
<!-- android transitions -->
1013
<item name="android:windowContentTransitions">true</item>
1114
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
1215
</style>
@@ -16,5 +19,10 @@
1619
<item name="color">@android:color/white</item>
1720
</style>
1821

22+
<style name="SlidingTextViewStyle" parent="@android:style/Widget.TextView">
23+
<item name="android:fontFamily">sans-serif-medium</item>
24+
<item name="android:textColor">#FFF</item>
25+
</style>
26+
1927

2028
</resources>

app/src/main/res/values/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<resources>
33

44
<!-- Theme colors -->
5-
<color name="theme_default_primary">#00BCD4</color>
6-
<color name="theme_default_primary_dark">#0097A7</color>
5+
<color name="theme_default_primary">#EC407A</color>
6+
<color name="theme_default_primary_dark">#E91E63</color>
77
<color name="theme_window_background">#2A2A2A</color>
88
<color name="accent">#EEFF41</color>
99
<color name="gray_row_color">#ff515252</color>

0 commit comments

Comments
 (0)