Thursday, 22 September 2016
Friday, 16 September 2016
Monday, 12 September 2016
Friday, 9 September 2016
Thursday, 8 September 2016
Tuesday, 6 September 2016
Tab Layout with Sliding Effect [ Fragment ]-Android Application
Source Code:
Main Activity:
package com.example.samin.slidinglayout_test01;import android.support.design.widget.TabLayout;import android.support.v4.content.ContextCompat;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class MainActivity extends AppCompatActivity {private TabLayout tabLayout;private ViewPager viewPager;private ViewPagerAdapter adapter;
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabLayout = (TabLayout) findViewById(R.id.tab_layout);viewPager = (ViewPager) findViewById(R.id.viewpager);/*Creating Adapter and setting that adapter to the viewPagersetSupportActionBar method takes the toolbar and sets it asthe default action bar thus making the toolbar work like a normalaction bar.*/adapter = new ViewPagerAdapter(getSupportFragmentManager());viewPager.setAdapter(adapter);/*TabLayout.newTab() method creates a tab view, Now a Tab view is not the viewwhich is below the tabs, its the tab itself.*///we also set the Test of the Tabsfinal TabLayout.Tab test01 = tabLayout.newTab();final TabLayout.Tab test02 = tabLayout.newTab();final TabLayout.Tab test03 = tabLayout.newTab();test01.setIcon(R.drawable.medicines);test02.setIcon(R.drawable.saved_items_inactive);test03.setIcon(R.drawable.alarm_inactive)tabLayout.addTab(test01,0);tabLayout.addTab(test02,1);tabLayout.addTab(test03,2);tabLayout.setTabTextColors(ContextCompat.getColorStateList(this,R.color.tab_selector));tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this,R.color.colorAccent));viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}@Overridepublic void onPageSelected(int position) {switch (position) {case 0:test01.setIcon(R.drawable.medicines);test02.setIcon(R.drawable.saved_items_inactive);test03.setIcon(R.drawable.alarm_inactive);break;case 1:test01.setIcon(R.drawable.medicines_inactive);test02.setIcon(R.drawable.saved_items);test03.setIcon(R.drawable.alarm_inactive);break;case 2:test01.setIcon(R.drawable.medicines_inactive);test02.setIcon(R.drawable.saved_items_inactive);test03.setIcon(R.drawable.alarm);break;}}@Overridepublic void onPageScrollStateChanged(int state) {}});tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {@Overridepublic void onTabSelected(TabLayout.Tab tab) {viewPager.setCurrentItem(tab.getPosition());}@Overridepublic void onTabUnselected(TabLayout.Tab tab) {}@Override
public void onTabReselected(TabLayout.Tab tab) { }});}
}
Sunday, 4 September 2016
Subscribe to:
Posts (Atom)