Tablayout , disable change between tabs with slide - java

I made a TabLayout and it's work fine , but I want to disable change between tabs with slide and make it change tabs only by clicking the tab name
is there a way to do it?

Just use the TabLayout without the ViewPager. In your onTabSelected, you load the view or fragment you want into the page container.

Related

onStop for Fragment in TabLayout to save some content

I have a TabLayout with two Tabs or Fragments.
In one Fragment I want to save for example text from edittext before switching tab or closing app.
I tried with onStop. It save the content before closing app. But when I go to second tab, the app closes without exception.
Why? Are the a solution for this problem?

Make ViewPager swipable through external layout / from outside

In my application I have an activity thats layout is basicly following:
App layout
The red part is a viewpager with fragments.
The blue part is a layout with buttons that doesnt change with swipe on viewpager.
But i want that the viewpager is swipable (smoothly) in the hole green framed area. It should act like normal viewpager behavior.
I have absolutely no idea if that is even possible or not, but hope it does.
I thought that it is maybe possible with a gestureoverlay or something, but don't know how to apply the detected gesture on the viewpager.
Only detecting swipe and set current page is not what I want achieve.
(I'm writing in java)
If the height of the viewpager and buttons layout are somewhat fixed, here is a solution:
1, use a ConstraintLayout as the root container
2, make viewpager the same size as the root, set the viewpager's padding to some value say 8dp
3, place the buttons layout over the view pager, taking up the bottom half space(except for some margin), the viewpager should still respond to touch where there is no button
4, for fragments inside view pager, use a ConstraintLayout to put the content at the top half of the page
I think this is what you are looking for
Nested Action Bar Tabs(with ViewPager)
There's also a demo on Github: https://github.com/r3dm4n/NestedActionBarTabswithViewPagerDEMO
Let me know if it helped

What is the best way to create pages(about/my home/references tabs) as in the image below?

I just started learning Android programming. I've created a page and I want to create "About/My Home/References" tabs in the image below.
The "About/My Home/References" tabs (you can see them in the link below) all act like a button. When I click the "About" tab, I can see the things about the users. When I click the "My Home" tab, I can see the some text about my home. The third tab also does the same thing.
Image link: https://imgyukle.com/i/4LgQH
My question is how can I do this in Android Studio? I've added three button but it doesn't look like that. Any idea?
You can use TabLayout with TabItems widgets. Visit, for example, https://material.io/develop/android/components/tab-layout/ for short overview and https://www.codingdemos.com/android-tablayout-example-viewpager/ as step-by-step manual.
For that layout, you want to use Fragments and a ViewPager with a TabLayout.
Your main Activity would contain 3 Fragments, AboutFragment, HomeFragment and ReferencesFragment.
This would allow you to build each layout separately. The ViewPager would contain the Fragment, and lets you swipe between them. The TabLayout contains your buttons, to tell the ViewPager which to show.

How to show a fixed number of tabs at a time in Android Material Design tabs?

I have used the Android Design Support library and implemented tabs in my android app using tablayout, fragments and viewpager. Tab sliding is working perfectly. But when I add more tabs (say 7), those tabs reduce their width and adjust themselves. How to show only 3 tabs at a time and show the next three when the user slides from 3rd to 4th tab?
In your MainActivity
ViewPager mpager;
TabPageAdapter adapter = new TabPageAdapter(getSupportFragmentManager(), list);
mtabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
mpager.setOffscreenPageLimit(list.size());
mpager.setAdapter(adapter);
In your xml TabLayout set
app:tabMode="scrollable"
you can use sliding tablayout
http://www.tutorialsbuzz.com/2015/04/Android-Material-Design-Sliding-TabLayout.html

Overlap a layout with viewPager

maybe you can help me. I want to use viewPager to overlap an other layout. so for example: I the first Fragment. On this Fragment is a picture, than I swipe to the right and then the second Fragment should just go over the first Fragment. It's like in the Android Youtube App in which you swipe from left to right and the settings and etc go over the main layout(like in the picture). Can you tell me what i have to do?
Thanks a lot, Vinzenz.
picture:
http://i.stack.imgur.com/CQ8gL.png
What you're asking for is actually not related to ViewPager. There is another layout you can use to implement the same navigation pane overlay: DrawerLayout link: http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

Categories

Resources