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 ↓
--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
--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
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