I'm new to android and would really appreciate some help.
I'm trying to show tabs at the bottom of my ViewPager. But the issue is that the TabLayout shows up without any text.
This is what I wrote inside UploadActivity.java class
public class UploadActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
ViewPager vpager = (ViewPager)findViewById(R.id.upload_viewpager);
PagerAdapter adapter = new UploadPagerAdapter(getSupportFragmentManager());
vpager.setAdapter(adapter);
}
public static class UploadPagerAdapter extends FragmentPagerAdapter{
String[] titles = new String[]{"Gallery", "Photo", "Video"};
public UploadPagerAdapter(FragmentManager manager){
super(manager);
}
@Override
public Fragment getItem(int position) {
switch(position){
case 0:
return new RestaurantListFragment();
case 1:
return new Fragment();
case 2:
return new Fragment();
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return titles[position];
}
@Override
public int getCount() {
return 3;
}
}
}
and inside XML, I have
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.raziabbasi.app.first.Activity.UploadActivity">
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/upload_viewpager"
android:layout_width="match_parent"
android:layout_height="355dp">
</android.support.v4.view.ViewPager>
<android.support.design.widget.TabLayout
android:id="@+id/upload-tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/White"
android:minHeight="25dp"
app:tabGravity="fill"
app:tabMode="fixed" />
</LinearLayout>
I have already tried multiple examples on SOC but that didn't help. Please advice.
Thanks in advance