Action bar Back button not working

前端 未结 13 1824
再見小時候
再見小時候 2020-12-01 03:13

with the help of these Android Docs.I am trying to do a action bar Back button.I get an Action Bar Back Button like these below image:

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 03:56

    I solved these problem by adding the below coding in GalleryActivity.

    ActionBar actionBar;
    actionBar=getActionBar();
    
    actionBar.setDisplayHomeAsUpEnabled(true);
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) { 
            switch (item.getItemId()) {
            case android.R.id.home: 
                onBackPressed();
                return true;
            }
    
        return super.onOptionsItemSelected(item);
    }
    

    In MainActivity:

    Previously,

    public class HomeActivity extends BaseActivity

    Then I change into

    public class HomeActivity extends FragmentActivity

    In GalleryFragment:

    I use Intent to pass it to the GalleryActivity.

    @Override
        public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
            Gallery gallery = (Gallery) arg0.getAdapter().getItem(arg2);
    
            Intent intent = new Intent(getActivity(), GalleryActivity.class);
            intent.putExtra("position", position);
            intent.putExtra("id", gallery.getGalId());
            intent.putExtra("name", gallery.getAlbumTitle());
            startActivity(intent);
    
            // mCallback.OnGalItemSelected(gallery.getGalId(),gallery.getAlbumTitle());
        } 
    

提交回复
热议问题