{"id":4033,"date":"2016-03-06T17:58:20","date_gmt":"2016-03-06T15:58:20","guid":{"rendered":"http:\/\/www.fandroid.info\/?p=4033"},"modified":"2016-03-06T18:08:26","modified_gmt":"2016-03-06T16:08:26","slug":"kak-sozdat-vkladki-tablayout-v-stile-material-design","status":"publish","type":"post","link":"https:\/\/www.fandroid.info\/kak-sozdat-vkladki-tablayout-v-stile-material-design\/","title":{"rendered":"\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043a\u043b\u0430\u0434\u043a\u0438 TabLayout \u0432 \u0441\u0442\u0438\u043b\u0435 Material Design"},"content":{"rendered":"

\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Android 5.0 Lolipop \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c\u00a0\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u043d\u0434\u0440\u043e\u0438\u0434-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0442\u0430\u0431\u043e\u0432 — \u0432\u043a\u043b\u0430\u0434\u043e\u043a. Tablayout \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043a\u043b\u0430\u0434\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n

\u0418\u0442\u0430\u043a, \u0432 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0447\u0438\u0442\u044c \u0432\u0430\u0441, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c tablayout \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0430, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f tablayout-\u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u043a\u043b\u0430\u0434\u043e\u043a \u043a \u043d\u0435\u043c\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043a\u043e\u043d\u043e\u043a \u044d\u0442\u0438\u043c \u0432\u043a\u043b\u0430\u0434\u043a\u0430\u043c.<\/p>\n

https:\/\/youtu.be\/LTT6dzj4jaQ<\/a><\/p>\n

package com.example.androidmaterialdesigntablayout;\r\n\r\nimport android.support.design.widget.TabLayout;\r\nimport android.support.v4.view.ViewPager;\r\nimport android.support.v7.app.ActionBar;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.support.v7.widget.Toolbar;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private Toolbar toolbar;\r\n    private TabLayout tabLayout;\r\n    private ViewPager viewPager;\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n\r\n        toolbar = (Toolbar) findViewById(R.id.toolbar);\r\n        setSupportActionBar(toolbar);\r\n        ActionBar actionBar = getSupportActionBar();\r\n        actionBar.setDisplayHomeAsUpEnabled(true);\r\n\r\n\r\n        viewPager = (ViewPager) findViewById(R.id.viewpager);\r\n        setupViewPager(viewPager);\r\n\r\n        tabLayout = (TabLayout) findViewById(R.id.tablayout);\r\n        tabLayout.setupWithViewPager(viewPager);\r\n\r\n\r\n    }\r\n\r\n    private void setupViewPager(ViewPager viewPager) {\r\n        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());\r\n        adapter.addFragment(new PeopleFragment(), \"People\");\r\n        adapter.addFragment(new PeopleFragment(), \"Group\");\r\n        adapter.addFragment(new PeopleFragment(), \"Calls\");\r\n        viewPager.setAdapter(adapter);\r\n    }\r\n\r\n}\r\n<\/pre>\n
package com.example.androidmaterialdesigntablayout;\r\n\r\nimport android.os.Bundle;\r\nimport android.support.v4.app.Fragment;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\n\r\n\r\npublic class PeopleFragment extends Fragment {\r\n\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n    }\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, ViewGroup container,\r\n                             Bundle savedInstanceState) {\r\n        return inflater.inflate(R.layout.peoplefragment, container, false);\r\n    }\r\n\r\n}\r\n<\/pre>\n
package com.example.androidmaterialdesigntablayout;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.support.v4.app.FragmentManager;\r\nimport android.support.v4.app.FragmentStatePagerAdapter;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n\r\npublic class ViewPagerAdapter extends FragmentStatePagerAdapter {\r\n\r\n\r\n    private final List<Fragment> mFragmentList = new ArrayList<>();\r\n    private final List<String> mFragmentTitleList = new ArrayList<>();\r\n\r\n    public ViewPagerAdapter(FragmentManager fm) {\r\n        super(fm);\r\n    }\r\n\r\n    @Override\r\n    public Fragment getItem(int position) {\r\n        return mFragmentList.get(position);\r\n    }\r\n\r\n    @Override\r\n    public int getCount() {\r\n        return mFragmentList.size();\r\n    }\r\n\r\n    @Override\r\n    public CharSequence getPageTitle(int position) {\r\n        return mFragmentTitleList.get(position);\r\n    }\r\n\r\n    public void addFragment(Fragment fragment, String title) {\r\n        mFragmentList.add(fragment);\r\n        mFragmentTitleList.add(title);\r\n    }\r\n\r\n}\r\n<\/pre>\n
<android.support.design.widget.CoordinatorLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\">\r\n\r\n    <android.support.design.widget.AppBarLayout\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:theme=\"@style\/ThemeOverlay.AppCompat.Dark\">\r\n\r\n        <android.support.v7.widget.Toolbar\r\n            android:id=\"@+id\/toolbar\"\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"?attr\/actionBarSize\"\r\n            android:background=\"?attr\/colorPrimary\"\r\n            app:layout_scrollFlags=\"scroll|enterAlways\" \/>\r\n\r\n        <android.support.design.widget.TabLayout\r\n            android:id=\"@+id\/tablayout\"\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            app:tabGravity=\"fill\"\r\n            app:tabMode=\"fixed\" \/>\r\n\r\n    <\/android.support.design.widget.AppBarLayout>\r\n\r\n    <android.support.v4.view.ViewPager\r\n        android:id=\"@+id\/viewpager\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\" \/>\r\n\r\n<\/android.support.design.widget.CoordinatorLayout>\r\n<\/pre>\n
<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:background=\"#e5e5e5\">\r\n\r\n    <ImageView\r\n        android:id=\"@+id\/imageView1\"\r\n        android:layout_width=\"100dp\"\r\n        android:layout_height=\"100dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_centerHorizontal=\"true\"\r\n        android:layout_marginTop=\"148dp\"\r\n        android:src=\"@mipmap\/ic_launcher\" \/>\r\n\r\n    <TextView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_below=\"@+id\/imageView1\"\r\n        android:gravity=\"center\"\r\n        android:text=\"People\"\r\n        android:textSize=\"30sp\" \/>\r\n\r\n<\/RelativeLayout>\r\n<\/pre>\n

\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Android 5.0 Lolipop \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c\u00a0\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u043d\u0434\u0440\u043e\u0438\u0434-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0442\u0430\u0431\u043e\u0432 — \u0432\u043a\u043b\u0430\u0434\u043e\u043a. Tablayout \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043a\u043b\u0430\u0434\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0418\u0442\u0430\u043a, \u0432 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0447\u0438\u0442\u044c \u0432\u0430\u0441, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c tablayout \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0438\u0437\u0430\u0439\u043d\u0430, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f tablayout-\u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f […]<\/p>\n","protected":false},"author":1,"featured_media":4037,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[3,63,19,14,136,5,138,132,133],"_links":{"self":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/4033"}],"collection":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/comments?post=4033"}],"version-history":[{"count":1,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/4033\/revisions"}],"predecessor-version":[{"id":4035,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/4033\/revisions\/4035"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/media\/4037"}],"wp:attachment":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/media?parent=4033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/categories?post=4033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/tags?post=4033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}