How to set the left right padding for a tab - android

I am trying to make a tab when swiped gives a padding between two fragment like this
I am making this with a support lib
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
My java code
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import com.astuetz.PagerSlidingTabStrip;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);
}
}
class TestAdapter extends FragmentPagerAdapter {
public TestAdapter (FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int i) {
Fragment fragment=null;
if (i==0){
fragment=new One();
}
if (i==1){
fragment=new Two();
}
if (i==2){
fragment=new Three();
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
String title = new String();
if (position==0){
return "tab1";
}
if (position==1){
return "tab2";
}
if (position==2){
return "tab3";
}
return title;
}
}
I tried to set the padding in viewpager but it is not working then I tried to set pstsTabPaddingLeftRight but it is also not working my xml code
LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
app:pstsShouldExpand="true"
app:pstsTextAllCaps="true"
app:pstsScrollOffset="7dp"
app:pstsIndicatorColor="#color/dem"
app:pstsDividerPadding="10dp"
app:pstsTabPaddingLeftRight="40dp"
/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/pager">
</android.support.v4.view.ViewPager>
</LinearLayout>
is there any other way to set the padding between any two tabs

Since you are using ViewPager, the easiest way to achieve some space is to use setPageMargin() method of Viewpager, which in your case will be
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setPageMargin(200);
//200 is value in pixel
There is also a method setPageMarginDrawable() sets a drawable that will be used to fill the margin between pages (Android documentation).

Related

how to set the title using tab layout

I am making an app implementing ViewPager and tab view but the title part is blank. please explain how to set the title for each fragments.
my MainActivity.java
package com.example.android.viewpager;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
/**
* Displays a {#link ViewPager} where each page shows a different day of the week.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
// Find the view pager that will allow the user to swipe between fragments
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
// Create an adapter that knows which fragment should be shown on each page
SimpleFragmentPagerAdapter adapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager());
// Set the adapter onto the view pager
if (viewPager != null) {
viewPager.setAdapter(adapter);
}
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
if (tabLayout != null) {
tabLayout.setupWithViewPager(viewPager);
}
}
}
my SimpleFragmentPagerAdapter class
package com.example.android.viewpager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
/**
* Provides the appropriate {#link Fragment} for a view pager.
*/
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
public SimpleFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 0) {
return new MondayFragment();
} else if (position == 1){
return new TuesdayFragment();
}
else if (position == 2){
return new WednesdayFragment();
}
else if (position == 3){
return new ThrusdayFragment();
}
else {
return new FridayFragment();
}
}
#Override
public int getCount() {
return 5;
}
}
my activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.android.viewpager.MainActivity">
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
In your SimpleFragmentPagerAdapter add the following code..containing your title string
private String tabTitles[] = new String[]{"Friends", "Suggested Friends", "Status"};
#Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
Or you can also use in your activity:
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
//add tab items with title..
tabLayout.addTab(tabLayout.newTab().setText("Friends"));
tabLayout.addTab(tabLayout.newTab().setText("Suggested Friends"));
tabLayout.addTab(tabLayout.newTab().setText("Status"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
by using below code, your fragment name will be set to your tab name.
String title = getItem(position).getClass().getName();
return title.subSequence(title.lastIndexOf(".") + 1, title.length());

TabLayout or horizontal scrollview Android

Image for the TabLayout that I wanted to achieve.
Can somebody shows me the way to achieve this?
My code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="center"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white" />
</LinearLayout>
I already set the attributes app:tabMode="scrollable" and app:tabGravity="center" but all the tabs just stick to the left in the layout.
I wanna achieve the result like the above image no matter how many the tabs are. Means the position of the tabs will away at the center or the tablayout.
PageFragment.java:
package com.example.testing;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
// In this case, the fragment displays simple text based on the page
public class PageFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
public static PageFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
PageFragment fragment = new PageFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_page, container, false);
TextView textView = (TextView) view;
textView.setText("Fragment #" + mPage);
return view;
}
}
SampleFragmentPagerAdapter.java:
package com.example.testing;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class SampleFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
private Context context;
public SampleFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
TabActivity.java:
package com.example.testing;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class TabAcitivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_layout);
// Get the ViewPager and set it's PagerAdapter so that it can display items
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager(),TabAcitivity.this));
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
}
}
The tabs start from the left. How do I place it to make it start at the middle? Or is it better to use a horizontal scrollable ListView?
use this for scrolling tabs:
sliding_tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
For any other reference please have a look at the following url.
https://guides.codepath.com/android/google-play-style-tabs-using-tablayout

The Titles do not appear in PagerTitleStrip at all on sdk 23 or 22

i have tried several things to display the text in the tabs on "scroll tabs" in my activity but it never shows
any ideas what happened?
below is the code:
scrollabletabs.xml:
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/pager">
<android.support.v4.view.PagerTitleStrip
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_gravity="top"
android:background="#color/material_deep_teal_500"
android:id="#+id/tabtitle"
style="#style/pagertitlestrip">
</android.support.v4.view.PagerTitleStrip>
</android.support.v4.view.ViewPager>
ScrolllableTabs.java:
package com.example.pc.learn_again;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
public class ScrollableTabs extends FragmentActivity {
//get the ViewPager//
ViewPager viewPager=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scrollabletabs);
viewPager = (ViewPager) findViewById(R.id.pager);
//the connection between the ViewPager and the adapter is below//
FragmentManager fragmentManager = getSupportFragmentManager();
viewPager.setAdapter(new myadapter(fragmentManager));
}
}
class myadapter extends FragmentPagerAdapter
{
public myadapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
//as you see from the below this is how we tell the Viewpager which fragment (page) to be shown//
Fragment fragment=null;
if (position==0)
{
fragment = new ScrollableFragment1();
}
if (position==1)
{
fragment = new ScrollableFragment2();
}
if (position==2)
{
fragment = new ScrollableFragment3();
}
return fragment;
}
#Override
public int getCount() {
return 3;//this is the number of pages
}
//the below is for the titles//
#Override
public CharSequence getPageTitle(int position) {
if (position==0)
{
return "Login Screen";
}
if (position==1)
{
return " List View";
}
if (position==2)
{
return "Calculator";
}
return null;
}
}
let me point out that the fragments appear correctly and they work fine , but i do not know why the titles in the tabs do not show (is it possible that the method returns null?? and if yes....why??)
thx for the help guys :)
Use:
<android.support.v4.view.PagerTabStrip
android:id="#+id/strip"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:textColor="#fff"
android:background="#android:color/holo_blue_bright"></android.support.v4.view.PagerTabStrip>
instead of
<android.support.v4.view.PagerTitleStrip
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_gravity="top"
android:background="#color/material_deep_teal_500"
android:id="#+id/tabtitle"
style="#style/pagertitlestrip">
The PageTabStrip worked for me.

Swipe not Working in android ViewPager using FragmentPagerAdapter

I want to create a swipe application for this I am using ViewPager in Android. When I run the code below, it runs successfully and a blue colored Fragment is opened, but swipe is not working on this. Can you tell me why?
This is the my Activity:
package app.learn.com.learnapp;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import java.util.List;
import java.util.Vector;
import menulistFrag.blueColor;
import menulistFrag.greenColor;
import menulistFrag.redColor;
public class MenuActivityList1 extends FragmentActivity {
ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_activity_list1);
viewPager = (ViewPager)findViewById(R.id.pager);
instantiateFrags();
}
public void instantiateFrags(){
List<Fragment> frags = new Vector<Fragment>();
frags.add(Fragment.instantiate(this, redColor.class.getName()));
frags.add(Fragment.instantiate(this, greenColor.class.getName()));
frags.add(Fragment.instantiate(this, blueColor.class.getName()));
PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(),frags);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(0);
}
}
This is my PagerAdapter:
package app.learn.com.learnapp;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
import menulistFrag.blueColor;
import menulistFrag.greenColor;
import menulistFrag.redColor;
/**
* Created by root on 13/9/15.
*/
public class PagerAdapter extends FragmentPagerAdapter {
List<Fragment> fragments;
public PagerAdapter(FragmentManager fm,List<Fragment> fragLists){
super(fm);
fragments =fragLists;
}
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
#Override
public int getCount() {
return 3;
}
}
I have three fragments:
redColor.java
greenColor.java
blueColor.java
And this is my layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pager">
</android.support.v4.view.ViewPager>
</LinearLayout>
Your instantiateFrags function is a bit strange - normally you should declare the fragments from within the PagerAdapter, and then instantiate the PagerAdapter itself from with the activity's onCreate method. Your code for the PagerAdapter could be something like the following:
public class PagerAdapter extends FragmentPagerAdapter {
int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int NumOfTabs){
super(fm);
this.mNumOfTabs = NumOfTabs;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
blueColor tab1 = new blueColor();
return tab1;
case 1:
greenColor tab2 = new greenColor();
return tab2;
case 2:
redColor tab3 = new redColor();
return tab3;
default:
return null;
}
}
#Override
public int getCount() {
return mNumOfTabs;
}
}
And then in your onCreate method in the main activity initialise the PagerAdapter (I have used a TabLayout here):
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Blue"));
tabLayout.addTab(tabLayout.newTab().setText("Green"));
tabLayout.addTab(tabLayout.newTab().setText("Red"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
PagerAdapter adapter = new PagerAdapter(
getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(
new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
xml for the tab layout and pager:
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:theme="#style/YOUR_THEME_HERE"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tab_layout"/>

Android - ActionBarActivity with ViewPager

i have a problem with ActionBarActivity and ViewPager.
On my "main-activity" which is a ActionBarActivity i have some tabs, which are fragments.
I want to implement the "swipe-feature" between these tabs.
I've already read the following tutorial:
http://developer.android.com/training/implementing-navigation/lateral.html
Actually i have implemented the whole code, but my app wont work. :(
There is no "swipe-feature" between the tabs.
Here is my code of the main-activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hauptmenue_extended);
try {
actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// ViewPager ...
pagerAdapter = new CollectionPagerAdapter(
getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(1);
viewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// Add all tabs to the actionbar...
Tab tabB = actionBar.newTab();
tabB.setText("Home");
tabB.setIcon(R.drawable.icon_home);
tabB.setTabListener(new TabListener<Startmenue_activity>(this,
"Start", Startmenue_activity.class, viewPager));
actionBar.addTab(tabB);
Tab tabA = actionBar.newTab();
tabA.setText("");
tabA.setIcon(R.drawable.icon_nachrichten_sel);
tabA.setTabListener(new TabListener<Nachrichten_activity>(this,
"News", Nachrichten_activity.class, viewPager));
actionBar.addTab(tabA);
Tab tabC = actionBar.newTab();
tabC.setText("");
tabC.setIcon(R.drawable.icon_favoriten);
tabC.setTabListener(new TabListener<Favoriten_activity>(this,
"Favs", Favoriten_activity.class, viewPager));
actionBar.addTab(tabC);
And my adapter looks like this:
public class CollectionPagerAdapter extends FragmentPagerAdapter {
final int NUM_ITEMS = 3; // number of tabs
List<Fragment> fragments = new ArrayList<Fragment>();
public Fragment getItem(int pos) {
return fragments.get(pos);
}
public void addFragment(Fragment f) {
fragments.add(f);
}
public CollectionPagerAdapter(FragmentManager fm) {
super(fm);
Fragment home_Fragment = new Startmenue_activity();
addFragment(home_Fragment);
Fragment news_Fragment = new Nachrichten_activity();
addFragment(news_Fragment);
Fragment favoriten_Fragment = new Favoriten_activity();
addFragment(favoriten_Fragment);
}
#Override
public int getCount() {
return NUM_ITEMS;
}
}
Oh and my XML of the main-activity looks like this:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Hauptmenue_extended" >
<!-- The ViewPager -->
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.view.ViewPager>
</android.support.v4.widget.DrawerLayout>
There's a bunch of things that I don't fully understand about your code, for example, why are you putting a ListView inside the ViewPager?. Anyways if you want to implement some tabs with the swipe feature. Here is how do it:
First the xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
Now the activity:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new SampleAdapter(this, getSupportFragmentManager()));
}
}
The adapter:
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class SampleAdapter extends FragmentStatePagerAdapter {
Context ctxt = null;
public SampleAdapter(Context ctxt, FragmentManager mgr) {
super(mgr);
this.ctxt = ctxt;
}
#Override
public int getCount() {
return 3;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new SimpleFragment("Hi");
case 1:
return new SimpleFragment("There");
case 2:
return new SimpleFragment("Fella");
}
return null;
}
#Override
public String getPageTitle(int position) {
switch (position) {
case 0:
return "First Tab";
case 1:
return "Second Tab";
case 2:
return "Third Tab";
}
return null;
}
}
And the SimpleFragment:
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
#SuppressLint("ValidFragment")
public class SimpleFragment extends Fragment {
String text;
public SimpleFragment(String string) {
text = string;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment, container, false);
TextView textview = (TextView) root.findViewById(R.id.textView1);
textview.setText(text);
return root;
}
}
And the fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Hope this helps :)
Try this out. But I've not tested it.
http://wptrafficanalyzer.in/blog/swipable-navigation-tabs-using-actionbarcompat-library/

Categories

Resources