2016-09-14 5 views
2

Ich baue Xamarin Android-Anwendung und möchte die rechte Navigationsleiste mit Schublade in einer benutzerdefinierten Aktionsleiste implementieren. Alles funktioniert (Schublade rutscht von der rechten Seite, ...) bis auf eine Sache: das Icon der Navigationsleiste wird nicht angezeigt.Symbol der Navigationsleiste wird nicht angezeigt

Also, das ist mein Activity.axml:

<?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.support.v4.widget.DrawerLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ffffff" 
      android:id="@+id/drawerLayout"> 

      <!-- Main Content --> 
      <FrameLayout xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <fragment 
        android:name="com.google.android.gms.maps.MapFragment" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scrollbars="vertical" 
        android:id="@+id/map" /> 
        ... 
      </FrameLayout> 

      <!-- Right Navigation Drawer --> 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="250dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="right" 
       android:background="#f2f2f2"> 
       ... 
      </LinearLayout> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

Und das ist mein Activity.cs:

using Android.Support.V4.App; 
using Android.Support.V4.Widget; 
... 

public class Activity : Activity 
{ 
    ... 
    private DrawerLayout mDrawerLayout; 
    private ActionBarDrawerToggle mDrawerToogle; 

    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 

     ActionBar.SetDisplayShowHomeEnabled(false); 
     ActionBar.SetDisplayShowTitleEnabled(false); 
     ActionBar.SetCustomView(Resource.Layout.CustomActionBar); 
     ActionBar.SetDisplayShowCustomEnabled(true); 

     SetContentView(Resource.Layout.Activity2); 

     mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout); 
     mDrawerToogle = new ActionBarDrawerToggle(this, mDrawerLayout, Resource.Drawable.ic_drawer,Resource.String.open_drawer_layout, Resource.String.close_drawer_layout); 

     mDrawerLayout.SetDrawerListener(mDrawerToogle); 
     ActionBar.SetDisplayHomeAsUpEnabled(true); 
     ActionBar.SetHomeButtonEnabled(true); 

     ... 
    } 

    protected override void OnPostCreate(Bundle savedInstanceState) 
    { 
     base.OnPostCreate(savedInstanceState); 
     mDrawerToogle.SyncState(); 
    } 

    public override void OnConfigurationChanged(Configuration newConfig) 
    { 
     base.OnConfigurationChanged(newConfig); 
     mDrawerToogle.OnConfigurationChanged(newConfig); 
    } 

    public override bool OnOptionsItemSelected(IMenuItem item) 
    { 
     if (mDrawerToogle.OnOptionsItemSelected(item)) 
     { 
      return true; 
     } 

     return base.OnOptionsItemSelected(item); 
    } 
    ... 
} 

Das ist mein Themes.xml:

<resources> 
    <style name="CustomActionBarTheme" 
    parent="@android:style/Theme.Holo.Light.DarkActionBar"> 
     <item name="android:actionBarStyle">@style/ActionBar</item> 
    </style> 
    <style name="ActionBar" 
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"> 
     <item name="android:height">75dp</item> 
     <item name="android:background">#00000000</item> 
    </style> 
</resources> 

Mache ich etwas falsch? Jede Hilfe wird geschätzt.

UPDATE

My CustomActionBar App-Symbol und App-Titel hat. Unterbindet dies möglicherweise das Icon der Navigationsleiste?

+0

sind Sie in der Lage, dies zu lösen? – user427969

+0

@ user427969 Ich habe meine Lösung unten gepostet, also stimme bitte, wenn es dein Problem gelöst hat – PeMaCN

Antwort

0

Dies ist die Lösung, die ich gefunden habe.

Zuerst müssen Sie action_bar.xml Datei mit folgendem Inhalt in dem Menü Ordner hinzufügen:

<?xml version="1.0" encoding="utf-8" ?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
    android:id="@+id/personalInfoActionBar" 
    android:title="Informations" 
    android:icon="@drawable/infoIcon" 
    android:showAsAction="always"/> 
</menu> 

Dann fügen Sie diesen Code in Ihrer Aktivität:

public override bool OnOptionsItemSelected(IMenuItem item) 
{ 
    if (item.ItemId == Resource.Id.personalInfoActionBar) 
    { 
     if (mDrawerLayout.IsDrawerOpen(mRightDrawer)) 
     { 
       mDrawerLayout.CloseDrawer(mRightDrawer); 
     } 
     else 
     { 
       mDrawerLayout.OpenDrawer(mRightDrawer); 
     } 

     return true; 
    } 

    return base.OnOptionsItemSelected(item); 
} 
0

Vergessen actionbarDrawerToggle.syncState nicht nennen()

+0

Ich rufe es in 'OnPostCreate()' Methode und wenn ich es in 'OnCreate()' Methode aufrufen wird es auch nicht angezeigt. – PeMaCN

+0

Ich denke, das Standard-DrawerToggle ist auf der linken Seite. Versuchen Sie, Ihre Schublade links zu platzieren, um zu prüfen, ob das Symbol angezeigt wird. Wenn es angezeigt wird, sollten Sie ein eigenes Symbol in der Aktionsleiste erstellen. – Chenmin

+0

Nein, das Symbol wird nicht angezeigt – PeMaCN

Verwandte Themen