The application icon does not show on action bar

前端 未结 6 1810
暗喜
暗喜 2020-11-29 02:06

I followed up the instructions of building a new android project and I got a runnable one except a problem with action bar. The problem is that the application icon is not s

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 02:44

    This is a common "problem".Before you pull your hairs out make sure you are using:

    import android.support.v7.app.ActionBar; //or the v4, haven't tried with that though
    

    and not:

    import android.app.ActionBar;
    

    and then:

    ActionBar actionBar;
    actionBar = getSupportActionBar();
    

    instead of:

    actionBar = getActionBar();

    And finally:

    if (actionBar != null) {
            // enabling action bar app icon and behaving it as toggle button           
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setIcon(R.drawable.your_icon);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
        }
    

提交回复
热议问题