Skip to content

Commit

Permalink
test(activity): sunflower sample中测试onOptionsItemSelected回调
Browse files Browse the repository at this point in the history
  • Loading branch information
donglua authored and shifujun committed Nov 25, 2019
1 parent 168445c commit 7cfb6d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.samples.apps.sunflower

import android.view.MenuItem
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil.setContentView
Expand All @@ -27,4 +28,14 @@ class GardenActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView<ActivityGardenBinding>(this, R.layout.activity_garden)
}

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
val id = item?.itemId
return if (id == android.R.id.home) {
onBackPressed()
true
} else {
super.onOptionsItemSelected(item)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class HomeViewPagerFragment : Fragment() {
}.attach()

(activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)

return binding.root
}
Expand Down

0 comments on commit 7cfb6d6

Please sign in to comment.