private void setUpPagerAndTabs() { pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new StreamMediaPlayerPagerAdapter(StreamVideoActivity.this, getSupportFragmentManager()); pager.setAdapter(pagerAdapter); pager.setOffscreenPageLimit(2); tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setTabsFromPagerAdapter(pagerAdapter); tabLayout.setupWithViewPager(pager); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { pager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { if (tab.getPosition() == 0) { pagerAdapter.mFragment.hideAll(); } } @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.people_org_pager, container, false); TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_org); tabLayout.addTab(tabLayout.newTab().setText("FOLLOWING")); tabLayout.addTab(tabLayout.newTab().setText("FOLOWERS")); tabLayout.addTab(tabLayout.newTab().setText("ORGANIZATIONS")); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager_org); final PagerOrgAdapter adapter = new PagerOrgAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.setOffscreenPageLimit(2); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); return view; }
private void setTabLayoutListeners(TabLayout tabLayout) { tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { switch (tab.getPosition()) { case 0: refreshTaskGrid(); break; case 1: refreshTaskGrid(); break; case 2: refreshTaskGrid(); break; } } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recommend); SwipeBackHelper.getCurrentPage(this).setSwipeBackEnable(false); ButterKnife.bind(this); back.setOnClickListener(v -> finish()); viewpager.setAdapter(pagerAdapter = new SeedFragmentListAdapter(getSupportFragmentManager())); tabs.setupWithViewPager(viewpager); viewpager.setCurrentItem(getIntent().getIntExtra("type", 0)); tabs.setTabTextColors( getResources().getColor(R.color.gray), getResources().getColor(R.color.orange)); tabs.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { title.setText(tab.getText()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
private void setUI() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { toolbar.setTitleTextColor(getResources().getColor(R.color.white)); } TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText(R.string.current_task)); // создание вкладок tabLayout.addTab(tabLayout.newTab().setText(R.string.done_task)); // создание вкладок final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabAdapter tabAdapter = new TabAdapter(fragmentManager, 2); // 2 - кол-во вкладок viewPager.setAdapter(tabAdapter); viewPager.addOnPageChangeListener( new TabLayout.TabLayoutOnPageChangeListener( tabLayout)); // слушатель на смены события вкладок tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem( tab.getPosition()); // передаем необходимый для отображения фрагмент } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override // выбран ранее выбранный таб public void onTabReselected(TabLayout.Tab tab) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); viewPager = (ViewPager) findViewById(R.id.tabanim_viewpager); setupViewPager(viewPager); Bitmap bm = decodeSampledBitmapFromResource(getResources(), R.drawable.fondo_chat_app, 500, 500); BitmapDrawable d = new BitmapDrawable(getResources(), bm); viewPager.setBackground(d); tabLayout = (TabLayout) findViewById(R.id.tabanim_tabs); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setupWithViewPager(viewPager); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); if (tab.getPosition() == 1) { if (hstl != null) { Log.d("NULL???", "No lo es"); // This in lanscape doesn't work...fix it! hstl.mostrarElems(); } else { Log.d("NULL???", "Lo es"); } } } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); // Change the icon android.support.v7.app.ActionBar ab = getSupportActionBar(); ab.setDisplayShowHomeEnabled(true); ab.setIcon(R.mipmap.logo_app_sin_pluma); ab.setTitle(""); // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { sendEmail(tr.getTxtTranslate()); Log.i("Send email", tr.getTxtTranslate()); } }); }
private void initTabs(View inflatedView) { TabLayout tabLayout = (TabLayout) inflatedView.findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab 3")); tabLayout.setOnTabSelectedListener(ContainerFragment3.this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_list); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE); if (mToolType == null) { throw new IllegalStateException("ToolType not available as extra; use startActivity"); } setTitle(mToolType.getToolNameResourceId()); // Set up tabs mViewPager = (ViewPager) findViewById(R.id.viewpager); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType); tabLayout.setTabsFromPagerAdapter(toolPagerAdapter); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); mViewPager.setAdapter(toolPagerAdapter); tabLayout.setOnTabSelectedListener(this); // Handle animation from previous activity postponeEnterTransition(); mViewPager .getViewTreeObserver() .addOnPreDrawListener( new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { mViewPager.getViewTreeObserver().removeOnPreDrawListener(this); startPostponedEnterTransition(); return true; } }); setEnterSharedElementCallback( new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { if (mViewPager.getCurrentItem() != 0) { // Not displaying the about page, which has the hero image names.clear(); sharedElements.clear(); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); tabLayout = (TabLayout) findViewById(R.id.tabLayout); pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new PagerAdapter(getFragmentManager())); tabLayout.addTab(tabLayout.newTab().setText(R.string.front)); tabLayout.addTab(tabLayout.newTab().setText(R.string.back)); if (savedInstanceState == null) { CountryIntentService.start(this, countryReceiver); } pager.setPageTransformer( true, new ViewPager.PageTransformer() { @Override public void transformPage(View page, float position) { page.setRotationY(180 * position); } }); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { pager.setCurrentItem(tab.getPosition(), false); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); pager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { tabLayout.getTabAt(position).select(); } @Override public void onPageScrollStateChanged(int state) {} }); }
private void setEvents() { tabLayout.setOnTabSelectedListener( new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); viewPager.setCurrentItem(tab.getPosition()); Log.d("Selected", "Selected " + tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { super.onTabUnselected(tab); Log.d("Unselected", "Unselected " + tab.getPosition()); } }); }
/** Setup the viewpager for current and past trip lists */ private void setupViewPager() { FragmentManager fm = getSupportFragmentManager(); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); if (viewPager != null) { int tabPosition = PreferencesUtils.getInt( mActivity, R.string.feed_list_selected_key, PreferencesUtils.Tab.FEED_LIST_UPCOMING); FeedPagerAdapter adapter = new FeedPagerAdapter(fm); viewPager.setAdapter(adapter); viewPager.setPageTransformer(true, new ZoomOutSlideTransformer()); viewPager.setCurrentItem(tabPosition, true); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); tabLayout.setSmoothScrollingEnabled(true); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { PreferencesUtils.setInt( mActivity, R.string.feed_list_selected_key, tab.getPosition()); viewPager.setCurrentItem(tab.getPosition(), true); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) { PreferencesUtils.setInt( mActivity, R.string.feed_list_selected_key, tab.getPosition()); } }); TabLayout.Tab tab = tabLayout.getTabAt(tabPosition); if (tab != null) { tab.select(); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_test); Intent i = getIntent(); doctor = (Doctor) i.getSerializableExtra("doc_details"); TextView name = (TextView) findViewById(R.id.detail_name); name.setText(doctor.getDoctor_name()); TextView category = (TextView) findViewById(R.id.detail_field); category.setText(doctor.getCaregory()); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("Details")); tabLayout.addTab(tabLayout.newTab().setText("Chambers")); tabLayout.addTab(tabLayout.newTab().setText("Comment")); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); final ViewPagerTabFragmentAdapter adapter = new ViewPagerTabFragmentAdapter( doctor, getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
private void initViewPager() { SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.container); viewPager.setAdapter(mSectionsPagerAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View ret = inflater.inflate(R.layout.fragment_discover, container, false); View btnSearch = ret.findViewById(R.id.discover_title_search); if (btnSearch != null) { btnSearch.setOnClickListener(this); } //////////////////////////////// tabBar = (TabLayout) ret.findViewById(R.id.discover_tab_bar); // TODO 因为Tab的设置是从网络来的,需要动态添加的 tabBar.setOnTabSelectedListener(this); ///////////////////////////////////////// pager = (ViewPager) ret.findViewById(R.id.discover_pager); // 设置Adapter // TODO 由于Tab动态设置的,所以 ViewPager Adapter 也需要动态设置 // ViewPager 在滑动页面的时候,添加监听 // 监听由 TabLayoutOnPageChangeListener 来完成 // 从而实现 ViewPager滚动,上面的TabLayout跟随滚动Tab pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabBar)); // 加载Tabs DiscoverTabTask task = new DiscoverTabTask(this); task.execute(); return ret; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_post__new__demand); this.toolbaractionbar = (Toolbar) findViewById(R.id.toolbar_actionbar); this.tablayout = (TabLayout) findViewById(R.id.tab_layout); tablayout.addTab(tablayout.newTab().setText("Diamond")); tablayout.addTab(tablayout.newTab().setText("Gems Stone")); tablayout.addTab(tablayout.newTab().setText("Jewellery")); tablayout.setTabGravity(TabLayout.GRAVITY_FILL); setSupportActionBar(toolbaractionbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); fragmentManager = getFragmentManager(); fragment = new DiamondFragment(); if (fragment != null) { fragmentManager.beginTransaction().add(R.id.container_tab, fragment).commit(); } tablayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { Log.d("tab position", String.valueOf(tab.getPosition())); switch (tab.getPosition()) { case 0: fragment = new DiamondFragment(); if (fragment != null) { fragmentManager .beginTransaction() .replace(R.id.container_tab, fragment) .addToBackStack("Diamond") .commit(); } break; case 1: fragment = new GemsStoneFragment(); if (fragment != null) { fragmentManager .beginTransaction() .replace(R.id.container_tab, fragment) .addToBackStack("GemsStones") .commit(); } break; case 2: fragment = new JewelleryFragment(); if (fragment != null) { fragmentManager .beginTransaction() .replace(R.id.container_tab, fragment) .addToBackStack("Jewellery") .commit(); } Log.d("tab 2", "tab 2 selected"); break; } } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dashboard); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setCustomView(R.layout.action_bar); TextView tab = (TextView) findViewById(R.id.mytext); tab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); editor = settings.edit(); editor.putString("Username", ""); editor.commit(); Intent intent = new Intent(getBaseContext(), Dashboard.class); startActivity(intent); } }); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); nestedScroll = (NestedScrollView) findViewById(R.id.mainscroll); nestedScroll.setFillViewport(true); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#007f12")); tabLayout.addTab(tabLayout.newTab().setText("DETAILS"), 0, true); tabLayout.addTab(tabLayout.newTab().setText("ADDRESS"), 1, false); mframeLayout = (FrameLayout) findViewById(R.id.content_frame); getSupportFragmentManager() .beginTransaction() .add(R.id.content_frame, new Sign_up_details()) .commit(); tabLayout.setOnTabSelectedListener(new OnTabSelectedListener()); bList = (ListView) findViewById(R.id.welcomelist); bList.setAdapter( new CustomAdapter(this, getResources().getStringArray(R.array.home_menu_array))); setListViewHeightBasedOnChildren(bList); bList.setOnTouchListener( new View.OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } }); bList.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { Intent intent = new Intent(getBaseContext(), MoneyTransferCalculator.class); startActivity(intent); } else if (position == 1) { settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); editor = settings.edit(); String asd = settings.getString("Username", ""); if (asd.length() == 0) { Intent intent = new Intent(getBaseContext(), Account.class); startActivity(intent); } else { Intent intent = new Intent(getBaseContext(), Dashboard_Fragment.class); startActivity(intent); } Intent intent = new Intent(getBaseContext(), Account.class); startActivity(intent); } else if (position == 2) { Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.jmtrax.net/")); startActivity(viewIntent); } else if (position == 3) { Intent viewintent = new Intent( "android.intent.action.VIEW", Uri.parse("http://www.jmtrax.com/money-laundering-statement/")); startActivity(viewintent); } else if (position == 4) { Intent intent = new Intent(getBaseContext(), Help.class); startActivity(intent); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); setContentView(R.layout.activity_schedule); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); Bundle fromrole = getIntent().getExtras(); role = fromrole.getString("role"); institution_code = fromrole.getString("institution_code"); institution_name = fromrole.getString("institution_name"); if (role.equals("Parent")) { child_username = fromrole.getString("child_username"); } Log.d("institution", institution_code + " " + institution_name); Tab = (ViewPager) findViewById(R.id.pager); Tab.setAdapter( new ScheduleTabsAdapter( getSupportFragmentManager(), role, institution_name, institution_code)); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(Tab); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { Tab.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { Tab.setCurrentItem(tab.getPosition()); } @Override public void onTabReselected(TabLayout.Tab tab) { Tab.setCurrentItem(tab.getPosition()); } }); /* Tab = (ViewPager)findViewById(R.id.pager); Tab.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar = getActionBar(); if (actionBar!=null) actionBar.setSelectedNavigationItem(position); } }); Tab.setAdapter(TabAdapter); actionBar = getActionBar(); if ( actionBar != null) { actionBar.setHomeButtonEnabled(true); } //Enable Tabs on Action Bar if ( actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } if ( actionBar != null) { Tab.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int postion) { actionBar.setSelectedNavigationItem(postion); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } */ /*ActionBar.TabListener tabListener = new ActionBar.TabListener(){ @Override public void onTabReselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { Tab.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub }}; */ // Add New Tab // actionBar.addTab(actionBar.newTab().setText("Android").setTabListener(tabListener)); // actionBar.addTab(actionBar.newTab().setText("iOS").setTabListener(tabListener)); // actionBar.addTab(actionBar.newTab().setText("Windows").setTabListener(tabListener)); } catch (Exception create_error) { Log.d("user", "error in create schedule activity: " + create_error.getMessage()); Toast.makeText(Schedule.this, "error " + create_error, Toast.LENGTH_LONG).show(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabs = (TabLayout) findViewById(R.id.tabs); List<String> titles = new ArrayList<>(); List<Fragment> fragments = new ArrayList<>(); String titlec = "职业生涯"; tabs.addTab(tabs.newTab().setText(titlec)); titles.add(titlec); Fragment fragment = new CareerF(); fragments.add(fragment); String titled = "日记"; tabs.addTab(tabs.newTab().setText(titled)); titles.add(titled); Fragment fragmentd = new Diary(); fragments.add(fragmentd); String titleb = "亲友生日"; tabs.addTab(tabs.newTab().setText(titleb)); titles.add(titleb); Fragment fragmentb = new Birthday(); fragments.add(fragmentb); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); TabLayViewPAdapter adapter = new TabLayViewPAdapter(getSupportFragmentManager(), titles, fragments); viewPager.setAdapter(adapter); tabs.setupWithViewPager(viewPager); tabs.setTabsFromPagerAdapter(adapter); tabs.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { index = tab.getPosition(); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); final FloatingActionButton actionButton = (FloatingActionButton) findViewById(R.id.bt_auction); actionButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { switch (index) { case 0: UIHelper.startAddCareer(MainActivity.this); break; case 1: break; case 2: UIHelper.startAddBirthday(MainActivity.this); break; } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cardset_picker); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); } }); mViewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { tabLayout.getTabAt(position).select(); } @Override public void onPageScrollStateChanged(int state) {} }); tabLayout = (TabLayout) findViewById(R.id.tabLayoutCardsetPicker); String[] mTabItems = getResources().getStringArray(R.array.tab_items_cardsetpicker); tabLayout.addTab(tabLayout.newTab().setText(mTabItems[0])); tabLayout.addTab(tabLayout.newTab().setText(mTabItems[1])); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); cardsetPickerFragment = new SearchCardsetFragment(); cardsetRecentsFragment = new RecentCardsetsFragment(); memorizer.freecoders.com.flashcards.FragmentManager.intUIState = Constants.UI_STATE_CARD_PICK; Multicards.setCardsetPickerActivity(this); }
public OrganizationView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.mContext = context; init(); mTabLayout.setOnTabSelectedListener(this); }
public OrganizationView(Context context) { super(context); this.mContext = context; init(); mTabLayout.setOnTabSelectedListener(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* Views */ toolbar = (Toolbar) findViewById(R.id.toolbar); list = (ListView) findViewById(R.id.listView); webView = (WebView) findViewById(R.id.webView); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); tabs = (TabLayout) findViewById(R.id.tabs); /* Tabs */ // Tabs are invisible hideTabs(); // Listener to receive tab changes tabs.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { // User selected new tab @Override public void onTabSelected(TabLayout.Tab tab) { // Find page for (Pages p : Pages.values()) { if (p.title.equals(actual.title)) { // Load URL in webview if (actual.url != null) actual.actualURL = p.url.split("\\|\\|")[tab.getPosition()]; if (actual.localPage != null) actual.actualAlternativeURL = actual.localPage.split("\\|\\|")[tab.getPosition()]; } } if (actual.url != null) { webView.loadUrl(actual.actualURL); } else { if (actual.localPage != null) webView.loadUrl("file:///android_asset/" + actual.actualAlternativeURL); } } // We don't need this methods @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); /* Drawer items */ // Create list of all items for the drawer final ArrayList<Pages> pages = new ArrayList<Pages>(); for (Pages p : Pages.values()) { if (p.menu == false) pages.add(p); } // Set actual page to the first item if (actual == null) { actual = pages.get(0); } /* White design */ if (actual.useWhiteFont) { toolbar.setTitleTextColor(0xFFFFFFFF); tabs.setTabTextColors(0xFFFFFFFF, 0xFFFFFFFF); } /* Toolbar */ toolbar.setTitle(actual.title); setSupportActionBar(toolbar); /* Admob */ AdView mAdView = (AdView) findViewById(R.id.adView); // Hide AdView when not needed if (!actual.useAds) { mAdView.setVisibility(View.INVISIBLE); } else { // Init AdView when needed AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } /* Drawer */ ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawerLayout.setDrawerListener(mDrawerToggle); drawerLayout.setDrawerShadow(R.drawable.shadow, Gravity.LEFT); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle.syncState(); /* Pages to drawer */ // Add pages to the drawer ListAdapter adapter = new ListAdapter(this, pages); list.setAdapter(adapter); adapter.notifyDataSetChanged(); /* Webview */ webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient( new WebViewClient() { // Handle URL loading // Handle Intents (e.g. mailto:) @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if ((url.contains("http:") || url.contains("https:")) && actual.homeDomains.contains(URI.create(url).getHost())) { view.loadUrl(url); return false; } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); PackageManager manager = getPackageManager(); List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0); if (infos.size() > 0) { startActivity(intent); } return true; } } // Needed for correct back-button functionality @Override public void onPageFinished(WebView view, String url) { webView.clearHistory(); super.onPageFinished(view, url); } // Handle loading errors @Override public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) { if (actual.actualAlternativeURL != null) webView.loadUrl("file:///android_asset/" + actual.actualAlternativeURL); else view.loadData(actual.error, "text/html", actual.localEncoding); } }); /* Site listener */ // Change page via drawer list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { changePage(pages.get(position)); } }); /* Update */ // Load actual (first) page changePage(actual); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); toolbar = (Toolbar) findViewById(R.id.toolbar); if (getResources().getBoolean(R.bool.is_wide)) { toolbar.setOnMenuItemClickListener( new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return true; } }); // Inflate a menu to be displayed in the toolbar toolbar.inflateMenu(R.menu.menu_main); } else { setSupportActionBar(toolbar); } viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); fab = (FloatingActionButton) findViewById(R.id.fab); tabLayout = (TabLayout) findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); if (!getResources().getBoolean(R.bool.is_wide)) { switch (tab.getPosition()) { case 0: fab.show(); getIntent() .putExtra( FloatingActionButtonBehavior.FAB_ENABLED_PARAM, FloatingActionButtonBehavior.FAB_ENABLED_TRUE); break; case 1: fab.hide(); getIntent() .putExtra( FloatingActionButtonBehavior.FAB_ENABLED_PARAM, FloatingActionButtonBehavior.FAB_ENABLED_FALSE); break; } } } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); }