I want to return to the previous screen with kotlin and java!

Introduction ...

This article was written in 5 previous articles,

** 6th day of article posting every day for 7 days **

It has become

I'll put the code to use below, but see the article five before for the detailed features of this app!

--java version: https://github.com/sato-na/guruwake_java

--kotlin version: https://github.com/sato-na/guruwake_kotlin

↓ This is the main subject of this article ↓

To return to the previous screen in each language ...

How to implement the toolbar

--For java

Toolbar variable name= findViewById(R.id.Toolbar id);
setSupportActionBar(variable);

Example)

WhoActiity.java


Toolbar whoTb = findViewById(R.id.who_tb);  //30th line
setSupportActionBar(whoTb);

--For kotlin

setSupportActionBar(Toolbar id)

Example)

WhoActivity.kt


setSupportActionBar(who_tb)  //21st line

java needs to create a ToolBar type variable, but kotlin doesn't need to

How to go back with the back button on the toolbar

--For java

(In the onCreate function)

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

(Outside the onCreate function)

@Override
public boolean onSupportNavigateUp() {
    finish();
    return super.onSupportNavigateUp();
}

Example) (In the onCreate function)

WhoActivity.java


getSupportActionBar().setDisplayShowHomeEnabled(true);  //32nd line
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

(Outside the onCreate function)

WhoActivity.java


@Override  //Line 69
public boolean onSupportNavigateUp() {
    finish();
    return super.onSupportNavigateUp();
}

--For kotlin

supportActionBar?.let {  //Line 22
    it.setDisplayHomeAsUpEnabled(true)
    it.setHomeButtonEnabled(true)
} ?: IllegalAccessException("Toolbar cannot be null")

AndroidManifest.xml


<activity
    android:name=".WhoActivity"
    android:parentActivityName=".MainActivity" />  //← Add here

Example)

WhoActivity.kt


supportActionBar?.let {  //Line 22
    it.setDisplayHomeAsUpEnabled(true)
    it.setHomeButtonEnabled(true)
} ?: IllegalAccessException("Toolbar cannot be null")

AndroidManifest.xml


<activity  //20th line
    android:name=".WhoActivity"
    android:parentActivityName=".MainActivity" />

java needs to define code and new functions, kotlin needs to edit code and AndroidManifest.xml

Finally…

This time I used the toolbar with java and kotlin to return to the previous screen. I felt that both languages required more complex code than screen transitions.

I will post an article tomorrow, so please keep an eye on me.

Recommended Posts

I want to return to the previous screen with kotlin and java!
I want to transition screens with kotlin and java!
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to implement various functions with kotlin and java!
I tried to summarize the basics of kotlin and java
[Java] I want to perform distinct with the key in the object
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I want to use java8 forEach with index
I want to display images with REST Controller of Java and Spring!
How to return to the previous screen by Swipe operation
[Java] I want to calculate the difference from the date
I want to control the start / stop of servers and databases with Alexa
I want to play a GIF image on the Andorid app (Java, Kotlin)
I want to dark mode with the SWT app
I want to get along with Map [Java beginner]
I want to return the scroll position of UITableView!
I tried to create a shopping site administrator function / screen with Java and Spring
I want to return an object in CSV format with multi-line header & filter in Java
I want to use screen sharing on the login screen on Ubuntu 18
I want to bring Tomcat to the server and start the application
I want to call a method and count the number
I want to use the Java 8 DateTime API slowly (now)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to distinct the duplicated data with has_many through
I want to transition to the same screen in the saved state
I want to return multiple return values for the input argument
I want to pass the startup command to postgres with docker-compose.
[Java] I want to test standard input & standard output with JUnit
I want to simplify the conditional if-else statement in Java
I tried to interact with Java
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
I want to give edit and delete permissions only to the poster
I want to create a chat screen for the Swift chat app!
I tried to summarize the methods of Java String and StringBuilder
I want to perform asynchronous processing and periodic execution with Rail !!!
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
I want to use DBViewer with Eclipse 2018-12! !!
[Spring Boot] I want to add my own property file and get the value with env.getProperty ().
I want to stop Java updates altogether
I went to the Java Women's Club # 1
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
[Active Admin] I want to customize the default create and update processing
[Ruby] I want to extract only the value of the hash and only the key
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want to get the IP address when connecting to Wi-Fi in Java
I want to ForEach an array with a Lambda expression in Java
I want to get the field name of the [Java] field. (Old tale tone)
I translated the grammar of R and Java [Updated from time to time]
I want to introduce the committee with Rails without getting too dirty
I tried to measure and compare the speed of GraalVM with JMH
I want to download a file on the Internet using Ruby and save it locally (with caution)
I want to test Action Cable with RSpec test
Kotlin functions and lambdas to send to Java developers
I want to output the day of the week
Run R from Java I want to run rJava
I tried to make Basic authentication with Java
I want to send an email in Java.
Try to link Ruby and Java with Dapr
I compared the characteristics of Java and .NET