2016-09-14 12 views
2

私はXamarin Androidアプリケーションを作成しています。カスタムアクションバーに引き出し付きの引き出しを実装したいと考えています。 1つのことを除いて、すべてが機能しています(引き出しが右側からスライドします...)。ナビゲーション用の引き出しアイコンは表示されません。ナビゲーション用の引き出しアイコンが表示されない

だから、これは私の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> 

そして、これは私の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); 
    } 
    ... 
} 

これは私の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> 

私が何か間違ったことをやっていますか?どんな助けもありがとうございます。

UPDATEは

私CustomActionBarは、アプリのアイコンとアプリのタイトルを持っています。これはナビゲーション引出しアイコンを中断している可能性がありますか?

+0

あなたはこれを解決することができましたか? – user427969

+0

@ user427969私の解決策を掲載しましたので、あなたの問題を解決したら投票してください – PeMaCN

答えて

0

これは私が見つけた解決策であることを忘れないでください。次に、あなたの活動にこのコードを挿入

<?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> 

まず、あなたはメニューフォルダに次の内容のaction_bar.xmlファイルを追加する必要が

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

呼び出すactionbarDrawerToggle.syncState()

+0

私は 'OnPostCreate()'メソッドで呼び出して、 'OnCreate()'メソッドで呼び出すとそれも表示されません。 – PeMaCN

+0

私はデフォルトのdrawerToggleが左側にあると思います。引き出しを左にして、アイコンが表示されていることを確認してください。表示されている場合は、アクションバーに独自のアイコンを作成する必要があります。 – Chenmin

+0

いいえ、アイコンが表示されていません – PeMaCN

関連する問題