0

I have implemented a chat activity and a search icon to search for texts. After entering the text, it will direct to another activity in order to display the texts. Now, I want to add a back arrow in my action bar or tool bar in order to go to the previous activity.

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var bundle: Bundle ? = intent.extras
        query = bundle?.getString("query") as String
        setSupportActionBar(chatSearchToolbar)

        setContentView(R.layout.activity_chat_search)
        loadQueryList(realm, query)
    }

chatSearchToolBar is my tool bar in XML file. How do I implement it?

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • That's java, this is kotlin – Bhavna Haritsa Apr 21 '19 at 00:56
  • So it would be... `supportActionBar.setDisplayShowHomeEnabled(true);` and in `onOptionsItemSelected()` You handle menuItemId by checking if it is `android.R.id.home` (or not handling it but declaring parentActivity in AndroidManifest `android:parentActivityName="..."`). – deadfish Jun 04 '19 at 13:39

0 Answers0