commit | dcb9b985623c0aabd135485ea864699a52d3eac6 | [log] [tgz] |
---|---|---|
author | Kirill Grouchnikov <kirillg@google.com> | Thu Nov 05 10:37:45 2015 -0500 |
committer | Kirill Grouchnikov <kirillg@google.com> | Thu Nov 05 10:37:45 2015 -0500 |
tree | 1d44d95d01296af7846ff23f7f2c7c7f4c4b48cb | |
parent | 9a86725ccacecf4ee34a28128ddd37ca1e1f756b [diff] |
Add "select tab" to the tab layout / view pager demo. Change-Id: I30c6b86a220692ef61a8e8eac5acd2952464f15c
diff --git a/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml b/samples/SupportDesignDemos/res/layout/design_tabs_viewpager.xml index b249155..f25a3ce 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 e65f140..c3a981a 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 ef776e0..8efccb5 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 @@ } } }); + + 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() {