I am trying to figure out how to have the icons not be on top of the text but rather to the side of it, but I am not sure how to do it with my code specifically. I am quite new to Android Studio so I would be grateful for any help.
XML Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MyCabinet">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarMyCabinet"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/colorPrimary">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/teacher_files_title"
android:gravity = "center"
android:id="@+id/toolbar_title"
app:fontFamily="@font/capriola"
android:textSize="20sp"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:elevation="4dp">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/viewPagerMyCabinet"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</LinearLayout>
The Activity Code
private TabLayout tabLayout;
private ViewPager viewPager;
private ViewPagerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_cabinet);
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
viewPager = (ViewPager) findViewById(R.id.viewPagerMyCabinet);
adapter = new ViewPagerAdapter(getSupportFragmentManager());
//add fragment here
adapter.AddFragment(new FragmentMyCabinet(), "My Cabinet");
adapter.AddFragment(new FragmentUpload(), "Upload");
adapter.AddFragment(new FragmentRecent(), "Recent");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.ic_folder);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_camera);
tabLayout.getTabAt(2).setIcon(R.drawable.ic_clock);
android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbarMyCabinet);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
ViewPagerAdapter
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<android.support.v4.app.Fragment> lstFragment = new ArrayList<>();
private final List<String> lstTitles = new ArrayList<>();
public ViewPagerAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
return lstFragment.get(position);
}
@Override
public int getCount() {
return lstTitles.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return lstTitles.get(position);
}
public void AddFragment(android.support.v4.app.Fragment fragment, String title) {
lstFragment.add(fragment);
lstTitles.add(title);
}
}
Here's what the UI looks like now: ui for app
I am not sure if I would have to create a custom xml or not, and if I did I am not too sure how to implement it smoothly into the code I have now.