Android - Back button in the title bar

前端 未结 26 2401
南方客
南方客 2020-12-04 07:02

In many apps (Calendar, Drive, Play Store) when you tap a button and enter a new activity, the icon in the title bar turns into a back button, but for the app I am making, i

26条回答
  •  情话喂你
    2020-12-04 07:28

    This is working for me.. Suppose there are two activity (Activityone,Activitytwo)

    Inside Activitytwo use this code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    

    On Activityone

    //when you need to go second activity
    startActivity(new Intent(Activityone.this, Activitytwo.class));
    

    This should be included in second activity inside manifest file

    
    

    And The result would be like this

提交回复
热议问题