将Arrow图标更改为Hamburger icon Android c#

时间:2018-10-11 10:02:38

标签: c# android xamarin icons

我在xamarin项目中实现了抽屉布局,并且出现了问题。 汉堡包显示得很好,可以正确滑动以变成箭头,但是当我尝试恢复汉堡包时,它将不再显示,而是停留在箭头上。我在以前的帖子中尝试了许多解决方案,但没有一个解决我的问题。

以下是屏幕的不同状态:

状态1

State 1 Image

状态2

State 2 Image

状态3

State 3 Image

这是我的代码:

public class HomeEventActivity : AppCompatActivity
{
    private SupportToolBar mToolBar;
    private MyActionBarDrawerToggle mDrawerToggle;
    private DrawerLayout drawerLayout;
    private ListView mLeftDrawer;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.HomeEvent);
        mToolBar = FindViewById<SupportToolBar>(Resource.Id.toolBarMenu);
        drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout1);
        mLeftDrawer = FindViewById<ListView>(Resource.Id.listviewleft);
        SetSupportActionBar(mToolBar);
        mDrawerToggle = new MyActionBarDrawerToggle(this, drawerLayout, Resource.String.openDrawer,
            Resource.String.closeDrawer);
        drawerLayout.AddDrawerListener(mDrawerToggle);
        SupportActionBar.SetDisplayHomeAsUpEnabled(true);
        SupportActionBar.SetHomeButtonEnabled(true);
        mDrawerToggle.SyncState();
        // Create your application here
        if (savedInstanceState != null)
        {
            if (savedInstanceState.GetString("DrawerState") == "Opened")
            {
                SupportActionBar.SetTitle(Resource.String.openDrawer);
                mDrawerToggle.SyncState();
            }
            else
            {
                SupportActionBar.SetTitle(Resource.String.closeDrawer);
                mDrawerToggle.SyncState();

            }
        }
        else
        {
            //This is the first time the activity is run
            SupportActionBar.SetTitle(Resource.String.closeDrawer);
            mDrawerToggle.SyncState();
        }
    }
    public override bool OnOptionsItemSelected(IMenuItem item)
    {
        mDrawerToggle.OnOptionsItemSelected(item);
        mDrawerToggle.SyncState();
        return base.OnOptionsItemSelected(item);
    }

    public override void OnSaveInstanceState(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        if (drawerLayout.IsDrawerOpen((int)GravityFlags.Left))
        {
           savedInstanceState.PutString("DrawerState", "Opened");
            mDrawerToggle.SyncState();
        }
        else
        {
            savedInstanceState.PutString("DrawerState", "Closed");
            mDrawerToggle.SyncState();
        }
        base.OnRestoreInstanceState(savedInstanceState, persistentState);
    }
    protected override void OnPostCreate(Bundle savedInstanceState)
    {
        base.OnPostCreate(savedInstanceState);
        mDrawerToggle.SyncState();
    }

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

有什么想法吗?

0 个答案:

没有答案