2016-05-09 3 views
0

Ich habe TabLayout aus der Support-Bibliothek implementiert, aber es überschreibt die ActionBar, die ich brauche.Aktionsleiste fehlt bei Verwendung von TabLayout

Layout

Dies ist die Aktivität, die es einrichtet und bläht die Laschen und lädt das Fragment für das Register.

public class TabsActivity extends android.support.v4.app.FragmentActivity { 


    FloatingActionButton fab; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_tabs); 

     setTitle("Fuel Logger"); 

     ActionBar a = getActionBar(); 




     ViewPager vp = (ViewPager) findViewById(R.id.viewpager); 
     vp.setAdapter(new FragmentPagerAdapter(
       getSupportFragmentManager(), TabsActivity.this 
     )); 

     TabLayout tabLayout = (TabLayout) findViewById(R.id.fuel_sliding_tabs); 
     tabLayout.setupWithViewPager(vp); 

    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.fuel_menu, menu); 
     MenuItem refresh = menu.findItem(R.id.action_settings); 
     refresh.setEnabled(true); 
     return true; 
    } 


    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(); 

     switch (id){ 
      case R.id.action_settings: 

       break; 
      case R.id.action_favorite: 

       return true; 

      default: 

     } 
      return super.onOptionsItemSelected(item); 
     } 


    } 

und die XML ist nur die Ansicht Pager und Tabula Layout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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 
     style="@style/FuelTabLayout" 
     android:id="@+id/fuel_sliding_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="scrollable" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="0px" 
     android:layout_weight="1.27" 
     android:background="@android:color/white" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@+id/fuel_sliding_tabs" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:src="@android:drawable/ic_menu_set_as" 
     app:layout_anchorGravity="bottom|right|end" 
     app:backgroundTint="@color/colorAccent" 
     android:layout_gravity="right" 
     android:cropToPadding="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginRight="20dp" 
     android:layout_marginEnd="20dp" 
     android:layout_marginBottom="20dp" /> 


</RelativeLayout> 

und ein Beispiel von Fragmenten Code, der mehr oder weniger das gleiche für jedes Fragment Klasse ist

Public class SummaryFragment extends android.support.v4.app.Fragment { 

public static final String ARG_PAGE = "SUMM_PAGE"; 
private int mTab; 

public static SummaryFragment newInstance(int page){ 
    Bundle args = new Bundle(); 
    args.putInt(ARG_PAGE, page); 
    SummaryFragment frag = new SummaryFragment(); 
    frag.setArguments(args); 
    return frag; 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mTab = getArguments().getInt(ARG_PAGE); 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_tab_summary, null); 


    return view; 
} 

Antwort

0

erste füge ToolBar hinzu und benutze LinearLayout mit horizontaler Ausrichtung und setze das im Stil NoActionBar hoffe es hilft dir

+0

sorry ich meine vartical – shlomo

Verwandte Themen