toolbarback-button-controlandroid-6.0-marshmallow

Android API 23 (Android 6.0) Toolbar implementation caused back button not working


I found there is issue with Android API 23 Toolbar implementation. Once I implemented Toolbar in my project, my device back button is not working (Android 2.3.6 Gingerbread phone). I tried switch back to Android API 21, it is working fine. Anyone has any idea how to fix Android API 23 Toolbar problem?

Thanks in advance!


Solution

  • EDIT: The latest version of support library (23.0.1) fixes this issue.

    Fixed an issue where hardware buttons did not work when an activity had set the Toolbar class to act as the ActionBar by using the setSupportActionBar() method. (Issue 183334)

    I have the exact same problem, but I cannot post a comment so commenting as an answer. Some code for reference:

    public class ActivitySettings extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Log.e("test","onBackPressed");
    }
    

    If I just remove these 2 lines, the onBackPressed gets called

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    

    This problem occurs only in android 2.3.x. Anything above that works fine.