2016-04-18 9 views
0

Ich möchte links oben auf dem Bildschirm eine Navigationsleiste mit allen darin enthaltenen Schaltflächen hinzufügen, damit Sie durch alle Aktivitäten navigieren können, während Sie sich auf einer anderen befinden.Navigationsablage oben links hinzufügen

Ich habe keine Ahnung, wie ich damit anfangen soll, kann mir jemand eine Hand geben?

Dies ist mein Code so weit, Main:

package com.example.rodekruis; 

import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.Button; 

public class MainActivity extends Activity implements View.OnClickListener{ 

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

     findViewById(R.id.button1).setOnClickListener(this); 
     findViewById(R.id.button2).setOnClickListener(this); 
     findViewById(R.id.button3).setOnClickListener(this); 
     findViewById(R.id.button4).setOnClickListener(this); 
     findViewById(R.id.button5).setOnClickListener(this); 
     findViewById(R.id.button6).setOnClickListener(this); 
     findViewById(R.id.button7).setOnClickListener(this); 
     findViewById(R.id.button8).setOnClickListener(this); 
     findViewById(R.id.button9).setOnClickListener(this); 
     findViewById(R.id.button10).setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     Intent intent = null; 
     switch (v.getId()) { 

      case R.id.button10: 
       intent = new Intent(MainActivity.this, AfspraakActivity.class); 
       break; 
      case R.id.button8: 
       intent = new Intent(MainActivity.this, BezoekActivity.class); 
       break; 
      case R.id.button9: 
       intent = new Intent(MainActivity.this, ContactActivity.class); 
       break; 
      case R.id.button3: 
       intent = new Intent(MainActivity.this, MeningActivity.class); 
       break; 
      case R.id.button4: 
       intent = new Intent(MainActivity.this, RouteActivity.class); 
       break; 
      case R.id.button1: 
       intent = new Intent(MainActivity.this, SpecialistenActivity.class); 
       break; 
      case R.id.button5: 
       intent = new Intent(MainActivity.this, BWCActivity.class); 
       break; 
      case R.id.button6: 
       intent = new Intent(MainActivity.this, AgendaActivity.class); 
       break; 
      case R.id.button7: 
       intent = new Intent(MainActivity.this, NieuwsActivity.class); 
       break; 
     } 
     startActivity(intent); 
    } 
} 

activity_main:

<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" 
    tools:context="com.example.rodekruis.MainActivity"> 


    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.rodekruis.MainActivity"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:src="@drawable/rkz_logo" 
     android:layout_gravity="center" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginBottom="20dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button10" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/button8" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Afspraak maken" /> 


     <Button 
      android:id="@+id/button8" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Bezoek tijden" /> 

     <Button 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Contact" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="20dp" 
     android:orientation="horizontal"> 


     <Button 
      android:id="@+id/button3" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Geef je mening!" /> 


     <Button 
      android:id="@+id/button4" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Route begeleiding" /> 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignLeft="@+id/button5" 
      android:layout_below="@+id/button8" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Specialisten" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button5" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1.03" 
      android:text="Brandwonden centrum" /> 


     <Button 
      android:id="@+id/button6" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text="Agenda" /> 


     <Button 
      android:id="@+id/button7" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Nieuws" /> 
    </LinearLayout> 

</LinearLayout> 
</LinearLayout> 
+0

Folgen Sie diesem Link: http://www.tutorialsbuzz.com/2014/03/android-sliding-menu-navigation-drawer.html –

Antwort

0

So erstellen Navigationsleiste Sie müssen als root Ihrer Ansicht verwenden DrawerLayout. Bitte beachten Sie, dass die Schwerkraft für die Ausrichtung der Navigationsschublade verantwortlich ist. Hier wird sie als Start angegeben, wie Sie links zeigen möchten.

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 
    <ListView android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="#111"/> 
</android.support.v4.widget.DrawerLayout> 

danach können Sie Listenansicht mit Tasten

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     mDrawerList = (ListView) findViewById(R.id.left_drawer); 

     // Set the adapter for the list view 
     mDrawerList.setAdapter(new ArrayAdapter<String>(this, 
       R.layout.drawer_list_item, mButtonTitles)) 

initialisieren, sobald es Onclick Zuhörer und offene entsprechenden Aktivitäten erfolgt definieren.

+0

Danke für die Reaktion. Wo muss ich den obigen Code in meiner Tätigkeit setzen? Oben auf der Aktivität, auf der Unterseite oder irgendwo in der Mitte? Ich bin nett weg neu zu diesem und wenn ich es oben setze, bekomme ich Fehler –

+0

Inside onCreate() -Funktion, da es die erste Methode ist, die in Activity lifecycle.i ausgeführt wird, schlägt Ihnen vor, durch Aktivitätslebenszyklus und für die weitere Navigation zu kommen Schublade klicke unten [link] (http://developer.android.com/training/implementing-navigation/nav-drawer.html) – Godather

Verwandte Themen