pizza / materialtabs Goto Github PK
View Code? Open in Web Editor NEWEasy-to-integrate tab bar with ripple effect for Android that completely respects Material Design for API 9+
License: MIT License
Easy-to-integrate tab bar with ripple effect for Android that completely respects Material Design for API 9+
License: MIT License
Is there an Tab Change event either the tab has been changed by code (setCurrentItem) or it has been scrolled/clicked?
It would be VERY VERY useful!
I've tried the demo app and I've found an issue that prevents me from using the library(for the moment).
The tab tile for "item two" it's partially shown, even when it's selected. On the phone(nexus 5) it's even worse, because it's showing only "two" instead of the full title "item two".
This can be also seen in the demo gif
I understand that the margins can show a glimpse of what's next, but we need to have at least the activated one that will show the full title text, in order to know the current tab.
Hi,
I'm using the following code snippet to declare my MaterialTabs in XML file:
<io.karim.MaterialTabs
android:id="@+id/material_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#FFFFFF"
android:textColor="#FF0000"
app:mtPaddingMiddle="false"
app:mtSameWeightTabs="true"
app:mtTextColorSelected="#00FF00"
/>
But I get only a white view, and its underlining indicator with default configuration.
But no text is displayed, and colors are not used when navigation through tabs.
Thank you in advance for your answer,
Regards.
Hi, your MaterialTabs a good library. But it will be very nice if you implement next feature. When user scrolling tabs layout, during scroll viewpager must to be scrolled with the tabs and the tab's indicator will update its state too. Anyway, thank you.
when i choose a tab diff. tab old not return color old
on android below 7.0. It worked good. But on Android 7.0. it not wokring
Hey, nice lib! It would be nice to have a parameter to change a custom font of textview in the tab.
How to get which tab is active, and is it posible to set active 3 tabs.
Error:(23, 0) Could not find property 'VERSION_NAME' on root project 'MaterialTabs-master'.
Implementing CustomTabViewProvider with the adapter works fine with Activities but throws null pointer exception when the tabs are used within the fragment.
Have you checked it ?
hi, i want to reduce padding left and padding right in Tab Item, i use same weight, i still want same weight, but reduce padding left and padding right of tab items so, user will not be necessary to scroll tab item because i want fixed tab width. thank you.
By default, MaterialTabs has a function to change the selected text color.
But in this instance, instead of using text in the tabs, I used getCustomTabView to change it into icon instead.
Now, how can I change the color of the icon when the user changes tabs?
hi i have tab bar and a view pager, i add another tab bar at the bottom and didnt connect the one and only viewpager to it since the first tab bar is using it and the second tab bar will take control of that and that is not my intention,i want to implement another tab bar at the bottom just to launch activities. can you tell me how to implement it via your library
thanks in advance
i've integrated material tabs inside my project in Lollipop successfully , but when i'm testing on samsung galaxy note 2 ,android 4.4.2 , Material tab colors changes to device default tab color which is blue ? should i use any configuration for compatibility?
MaterialTabs
depends on a ViewPager
, which in turn depends on a PagerAdapter
. If the PagerAdapter
is modified to return a lower value from getCount()
than it had returned earlier, and if the selected tab's position is beyond the new getCount()
, when we call notifyDataSetChanged()
to update the PagerAdapter
, MaterialTabs
crashes. Exactly where and how it crashes depends a bit on the timing of events, but one common spot is what is currently line 443, where from what I can tell tabsContainer.getChildAt(position)
returns null
.
This sample project can be used to illustrate the problem, though I presently have a workaround set up. Here, the ViewPager
has either 3 or 10 pages, based on the state of a "Fixed" checkable overflow item. In onOptionsItemSelected()
, I need to adjust things based on the current checked state of that MenuItem
:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.fixed) {
item.setChecked(!item.isChecked());
if (item.isChecked()) {
if (pager.getCurrentItem()>2) {
pager.setCurrentItem(2);
}
pager.postDelayed(new Runnable() {
@Override
public void run() {
adapter.setPageCount(3);
adapter.notifyDataSetChanged();
}
}, 100);
}
else {
adapter.setPageCount(10);
adapter.notifyDataSetChanged();
}
return(true);
}
return(super.onOptionsItemSelected(item));
}
My original implementation just called setPageCount(3)
on my SampleAdapter
(subclass of FragmentPagerAdapter
), then notifyDataSetChanged()
. MaterialTabs
crashed.
I then tried calling pager.setCurrentItem(2)
before setPageCount(3)
, to try to switch the selected tab into the newly-safe range before reducing the page count. MaterialTabs
crashed. Near as I can tell, it did not pick up the ViewPager
current-item change before trying to deal with the page-count change.
I then tried moving the setPageCount(3)
and notifyDataSetChanged()
into a simple post()
Runnable
. That too tended to crash. Making it postDelayed(..., 100)
gave me more reliable results. But any time we use post()
/postDelayed()
to try to postpone work until some other work gets done first, $DEITY
kills a $CUTE_ANIMAL
.
To reproduce the problem, roll back to my original implementation:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.fixed) {
item.setChecked(!item.isChecked());
if (item.isChecked()) {
adapter.setPageCount(3);
adapter.notifyDataSetChanged();
}
else {
adapter.setPageCount(10);
adapter.notifyDataSetChanged();
}
return(true);
}
return(super.onOptionsItemSelected(item));
}
Then:
You should get one variation of the crash, dying on line 334:
java.lang.NullPointerException
at io.karim.MaterialTabs.scrollToChild(MaterialTabs.java:334)
at io.karim.MaterialTabs.access$1200(MaterialTabs.java:50)
at io.karim.MaterialTabs$3.onGlobalLayout(MaterialTabs.java:407)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:808)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1768)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Note that your existing code seems to handle expanding the number of pages just fine. It also works fine if the selected page is in the range of pages that is being retained (i.e., its position is inside the new getCount()
value).
IMHO, asking us to move the selected page to a safe spot ourselves (via setCurrentItem()
) is reasonable if you need that, but it really should not require us to then postDelayed()
the actual page count change.
Thanks!
Can't remove all-caps from the tab titles in Lollipop.
Tried using app:mtTextAllCaps, tabs.setAllCaps(false) and even;
TextView tab_title = (TextView) tabs.findViewById(io.karim.materialtabs.R.id.mt_tab_title);
tab_title.setAllCaps(false);
with no luck.
Hi!
The demo looked impressive, I wanted to give it a try, but I got the following Gradle error:
Failed to resolve: com.github.pizza:MaterialTabs:2.0.3
As other projects from jitpack.io compile successfully I think that it must be an issue with MaterialTabs.
Thanks,
Robert
Hi, I have just installed your sample from the play market. However, it's crashing after choosing the second configuration of tabs, i.e.
launched app->configuration selected -> open tabs ->back->configured again->opening results in crash.
Xperia Z1 compact, Lolipop 5.0.1
Unfortunately, I haven't so much time now, maybe I'll look deeper inside your sample later :)
Hey,
I am seeking to add the count in the tabs. Similar to what WhatsApp has done. Is there any straight way of doing it or is there any way to get the tab view and update it.
Thank you.
I want the tabs but the fragments are replaced in the FrameLayout
by FragmentTransaction
.
but there is no method to add tabs programmatically. How can i do this?
When I have no tabs, the Actionbar, by default, drops a nice shadow. How to get a similar shadow for the MaterialTabs?
ICYMI, Google Play Store app tabs show a shadow and so does Whatsapp.
how can we customize the fonts used in this library ??
@OverRide
public View getCustomTabView(ViewGroup parent, int position) {
ImageView imageView = new ImageView(MainActivity.this);
imageView.setImageResource(UNSELECTED_ICONS[position]);
return imageView;
}
@Override
public void onCustomTabViewSelected(View view, int position, boolean alreadySelected) {
Log.i(TAG, "custom tab view selected with position = " + position);
if (view instanceof ImageView) {
((ImageView) view).setImageResource(SELECTED_ICONS[position]);
}
}
@Override
public void onCustomTabViewUnselected(View view, int position, boolean alreadyUnselected) {
Log.i(TAG, "custom tab view unselected with position = " + position);
if (view instanceof ImageView) {
((ImageView) view).setImageResource(UNSELECTED_ICONS[position]);
}
}
used this implements. But icon size are to big. Is there any way to set width and height of icon
the sample app on google play have an error
So, I have school timetable with 1 Tab activity with 1 fragment (5 tabs) which displays listview, populated with ArrayList rows through custom Adapter.
Problem occurs when switching content through Tabs. If I scroll out of screen (un-cache), make it offscreen and then scroll back to that Tab, I get correct ArrayList.
If needed, can provide code.
Is there any problem to implement with nested fragments?
I couldnt make it work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.