Skip to main content

Posts

Showing posts with the label Toolbar

android kotlin - Toolbar menu example

MainActivity.kt package com.example.jetpack import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // set toolbar as support action bar setSupportActionBar(toolbar).apply { title = "Toolbar Menu Example" } } // show the menu on toolbar override fun onCreateOptionsMenu(menu: Menu?): Boolean { val inflater = menuInflater inflater.inflate(R.menu.toolbar_menu,menu) return super.onCreateOptionsMenu(menu) } // toolbar menu item click listener override fun onOptionsItemSelected(item: MenuItem): Boolean { when(item.itemId){ R.id.download->{ te...

Android Kotlin: How to change Toolbar back button color

Customizing the Toolbar Back Button Color in Android (Kotlin) This code demonstrates how to change the color of the back button displayed on the Toolbar in an Android application written in Kotlin. It includes two activities: a MainActivity and a SecondActivity. The MainActivity serves as the starting point and displays a simple button to navigate to the SecondActivity. The SecondActivity showcases the back button customization. Breakdown of the Code: The code consists of several parts: Activity Classes (MainActivity.kt & SecondActivity.kt): These files define the functionalities of each activity. They handle setting up the layout, toolbar, and button click listener. Layout Resource Files (activity_main.xml & activity_second.xml): These files define the visual structure of each activity using ConstraintLayout and include elements like Toolbar and Button. Styles (res/values/styles.xml): This file defines the base theme for the application, including color attribute...

Android Kotlin: Toolbar back button example

Toolbar Back Button The following kotlin tutorial will demonstrate to us how we can show a back button on the Toolbar and how we can navigate back to the previous activity using the Toolbar back button click event in an android application. To do this we selected an android theme that has an ActionBar. We create two Activity screens so that we can navigate between them. The first Activity is the main activity. In this main activity kotlin file, we called the support ActionBar and set a title for it.We also put a Button widget on this main activity and we navigate to the second activity using its click event. The Intent is used to navigate from the main activity to the other activity. We created another Activity named the second activity. We navigate this activity from the main activity using the main activity Button’s click event. But how can we navigate from the second activity to the main activity because in this second activity we don’t pla...