ActionBar Swipe2 Menu





MyActivity.java
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.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class MyActivity extends ActionBarActivity {
 
 protected void onCreate(Bundle arg0) {
  super.onCreate(arg0);
  setContentView(R.layout.activity_my);
  
  PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
  ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(adapter); 
 }
 
 

 
 public class PagerAdapter extends FragmentPagerAdapter {

  public PagerAdapter(FragmentManager fm) {
   super(fm);
  }

  public Fragment getItem(int arg0) {
   switch (arg0) {
             case 0:
                 return new Fragment_Productos();
             case 1:
                 return new Fragment_Clientes();
             case 2:
                 return new Fragment_Pedidos();
             default:
              return null;
   }
  }

  public int getCount() {
   return 3;
  }
  
  public CharSequence getPageTitle(int position) {
   String titulo = null;
   switch (position) {
    case 0:
                 titulo = "PRODUCTOS";
                 break;
             case 1:
              titulo = "CLIENTES";
                 break;
             case 2:
              titulo = "PEDIDOS";
                 break;
   }
   return titulo;
  }
    } 
}

activity_my.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.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:textColor="#000"
        android:paddingTop="4dp"
        android:paddingBottom="4dp" />

</android.support.v4.view.ViewPager>

Fragment_Pedidos.java
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;

public class Fragment_Pedidos extends Fragment {
 
 View rootView;
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  rootView = inflater.inflate(R.layout.fm_pedidos, container, false); 
  return rootView;
 } 
}

Fragment_Clientes.java
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;

public class Fragment_Clientes extends Fragment {
 View rootView;
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  rootView = inflater.inflate(R.layout.fm_clientes, container, false); 
  return rootView;
 } 
}

Fragment_Productos.java
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;

public class Fragment_Productos extends Fragment {
 
 View rootView;
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  rootView = inflater.inflate(R.layout.fm_productos, container, false); 
  return rootView;
 } 
}

fm_clientes.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
 <TextView 
     android:id="@+id/texto_clientes"
            android:text= "soy cliente"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:gravity="center"/>
 
</LinearLayout>


fm_pedidos.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
 <TextView 
     android:id="@+id/texto_pedidos"
            android:text="soy pedidos"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:gravity="center"/>
 
</LinearLayout>

fm_productos.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
 <TextView 
     android:id="@+id/texto_productos"
            android:text="soy producto"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:gravity="center"/>
 
</LinearLayout>

3 comentarios:

  1. Hola Hola estoy tratando de poner este actionbar en un fragment, es posible hacer esto? que un fragment contenga otros fragment!

    ResponderEliminar