I have a ViewPager
and TabLayout
with 5 slides and am looking for dots to indicate which slide the user is on, per this SO question.
My code:
slider.xml:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.TabLayout
android:id="@+id/dots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:alpha=".5"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabPaddingEnd="6dp"
app:tabPaddingStart="6dp"
/>
tab_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape
android:shape="ring"
android:innerRadius="0dp"
android:thickness="4dp"
android:useLevel="false">
<solid android:color="@android:color/holo_red_dark"/>
</shape>
</item>
<item>
<shape
android:shape="ring"
android:innerRadius="0dp"
android:thickness="3dp"
android:useLevel="false">
<solid android:color="@android:color/holo_orange_light"/>
</shape>
</item>
</selector>
fragment_first_screen.xml: (an image holder)
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_bg_first_screen">
<ImageView
android:id="@+id/first_screen_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/transparent"
android:contentDescription="p"
android:scaleType="fitCenter"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</android.support.constraint.ConstraintLayout>
slider.java
public class FirstScreensActivity extends FragmentActivity {
private ViewPager pager;
private TabLayout indicator;
indicator = findViewById(R.id.dots);
pager = findViewById(R.id.pager);
pager.setAdapter(adapter);
indicator.setupWithViewPager(pager, true);
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
bundle.putInt("imgResource", imgResources[position]);
FirstScreenFragment fragment = new FirstScreenFragment();
fragment.setArguments(bundle);
return fragment;
}
@Override
public int getCount() {
return imgResources.length;
}
};
}
The dots are not visible, but I know the tabs are there because I can navigate by touching them. And the TabLayout background is a solid white, blank bar. So neither dots nor tab selector indicators are visible and I don't know why. I've tried numerous examples and can't get the dots to appear. AS 3.5.1 (28)