Android - Back button in the title bar

前端 未结 26 2335
南方客
南方客 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:18

      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.YourxmlFileName);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    
      public boolean onOptionsItemSelected(MenuItem item) {
            int id = item.getItemId();
    
            if (id==android.R.id.home) {
                finish();
                return true;
            }
            return false;
        }
    

提交回复
热议问题