簡體   English   中英

打開抽屜時,Android導航抽屜圖標恢復為默認設置

[英]Android Navigation Drawer Icon reverting to default when Drawer is open

我的導航抽屜圖標有問題。
我們將默認的“后插入符號”替換為使用其他圖標,並且效果很好。

但是,如果導航抽屜已經打開並且用戶旋轉了設備,則圖標將恢復為默認的插入符號,並且直到導航抽屜關閉並且活動的onCreate()方法都不會返回到自定義圖標。再次調用(通常通過旋轉設備)。

這是代碼:

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

    // set the toolbar as the action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_drawer);
    setSupportActionBar(toolbar);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new StartFragment())
                .commit();
    }

    //Init the GameLog
    GameLog.init(this);
}

/**
 * Initializes the DrawerLayout for the particular activity
 */
public static void init(Activity activity) {
    mActivity = activity;
    mDrawerLayout = (DrawerLayout)activity.findViewById(R.id.drawer_layout);
    mRecyclerView = (RecyclerView)activity.findViewById(R.id.left_drawer);

    //set adapter
    mRecyclerView.setAdapter(mAdapter);
    //set layout manager
    mRecyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
    //add a divider between elements
    mRecyclerView.addItemDecoration(
            new HorizontalDividerItemDecoration.Builder(activity)
                    .color(Color.WHITE)
                    .build());

    Toolbar toolbar = (Toolbar)((ActionBarActivity)activity).getSupportActionBar().getCustomView();

    mDrawerToggle = new ActionBarDrawerToggle(activity, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (activity.getActionBar() != null) {
        activity.getActionBar().setDisplayHomeAsUpEnabled(true);
        activity.getActionBar().setHomeButtonEnabled(true);
    }

}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    GameLog.getToggle().syncState();
}

希望這是有道理的。

謝謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM