-
Notifications
You must be signed in to change notification settings - Fork 58
Custom IndicatorManager
Ruben Gees edited this page Sep 17, 2015
·
3 revisions
To get started, extend the IndicatorManager
class like the following:
public class NumberIndicatorManager extends IndicatorManager {
@Override
public View init(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent,
int slideAmount) {
//We need to implement this.
return null;
}
@Override
public void select(int position) {
//And this also.
}
}
The next thing we need is a layout. To achieve the effect of the image above, you could do something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/introduction_indicator_number_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white" />
</FrameLayout>
Now we need to inflate the layout and implement the logic for it in our previously created class NumberIndicatorManager
:
@Override
public View init(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent,
int slideAmount) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_indicator_layout_number, parent,
false);
text = (TextView) root.findViewById(R.id.introduction_indicator_number_text);
this.slideAmount = slideAmount //Save the amount of slides for later.
//Don't add the inflated View to the parent here. That will be done for you by the lib.
return root;
}
@Override
public void select(int position) {
text.setText((position + 1) + "/" + slideAmount);
}
Great! That should work. Now we need to pass our NumberIndicatorManager
to the IntroductionBuilder:
new IntroductionBuilder(this).withSlides(generateSlides())
.withIndicatorManager(new NumberIndicatorManager()).introduceMyself();