diff options
author | Kirill Grouchnikov <kirillg@google.com> | 2015-11-05 10:37:45 -0500 |
---|---|---|
committer | Kirill Grouchnikov <kirillg@google.com> | 2015-11-05 10:37:45 -0500 |
commit | fffb2474d2aa360caab8084d0e3e68290f2a1530 (patch) | |
tree | 24d3fc025fff401254852fa184b035d22ccaed91 | |
parent | 8d3349a080d2a18ee76400fc86dccb1efb7e1650 (diff) | |
download | android_development-fffb2474d2aa360caab8084d0e3e68290f2a1530.tar.gz android_development-fffb2474d2aa360caab8084d0e3e68290f2a1530.tar.bz2 android_development-fffb2474d2aa360caab8084d0e3e68290f2a1530.zip |
Add "select tab" to the tab layout / view pager demo.
Change-Id: I30c6b86a220692ef61a8e8eac5acd2952464f15c
3 files changed, 16 insertions, 0 deletions
diff --git a/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml b/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml index b249155ed..f25a3ce5f 100644 --- a/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml +++ b/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml @@ -62,6 +62,12 @@ android:layout_height="wrap_content" android:text="@string/remove_tab"/> + <Button + android:id="@+id/btn_select_first_tab" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/select_first_tab"/> + </LinearLayout> <RadioGroup diff --git a/samples/SupportDesignDemos/res/values/strings.xml b/samples/SupportDesignDemos/res/values/strings.xml index e65f1403a..c3a981a02 100644 --- a/samples/SupportDesignDemos/res/values/strings.xml +++ b/samples/SupportDesignDemos/res/values/strings.xml @@ -49,6 +49,7 @@ <string name="add_tab">Add tab</string> <string name="remove_tab">Remove tab</string> + <string name="select_first_tab">Select tab #0</string> <string name="form_username">Username</string> <string name="form_email">Email address</string> diff --git a/samples/SupportDesignDemos/src/com/example/android/support/design/widget/TabLayoutUsage.java b/samples/SupportDesignDemos/src/com/example/android/support/design/widget/TabLayoutUsage.java index ef776e0c6..8efccb530 100644 --- a/samples/SupportDesignDemos/src/com/example/android/support/design/widget/TabLayoutUsage.java +++ b/samples/SupportDesignDemos/src/com/example/android/support/design/widget/TabLayoutUsage.java @@ -85,6 +85,15 @@ public class TabLayoutUsage extends AppCompatActivity { } } }); + + findViewById(R.id.btn_select_first_tab).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mTabLayout.getTabCount() > 0) { + mViewPager.setCurrentItem(0); + } + } + }); } private void addRandomTab() { |