The environment for using kotlin was set up last time. Next, let's actually create a project.
When you start Android Studio, a window similar to the "welcome screen" in Xcode opens. ・ Android Studio ・ Xcode At first there is no project, so click "Start a new Android Studio project". First, decide on a name for the entire project. Unless otherwise specified, "My Application" entered by default is OK.
Enter the environment in which the next application to be created will run. Basically, there is no problem with "Phone and Tablet" (if you want to make something that works in other environments, please select it appropriately). Then select the Android version. As of March 2017, Ice Cream Sandwich (version 4.0) is selected as standard.
Unlike iOS, Android needs to support multiple versions. In the case of iOS, basically you can use the latest version on any device (about 4S has been cut recently), and even if it is old, there is no problem if you go back about 2 generations, but Android is for each device. You need to be aware that the available versions are limited and there are always so many versions. Currently, the latest Android is Nougat (version 7.0), but considering the models currently on the market, it is safe to make it compatible with IceCream Sandwich (version 4.0).
Select the target device and select "Next".
This screen is in Xcode
This is the corresponding part.
There are various templates available, but it's okay if you choose "Empty Activity".
Finally, give a name to the layout file that corresponds to Activity (like ViewController in Xcode) and the project is complete.
I would like you to look at this screen a little carefully, but the standard input is Activity Name is "Main Activity" and Layout Name is "activity_main". This is actually quite important, but on Android, one screen is composed of two types: "XML layout file that displays the screen" and "Activity file by Java (kotlin) that sets the movement of the screen". It's the same feeling as putting a view controller on the storyboard in Xcode and making the swift file correspond to it, but in Xcode you can set it on the storyboard, but in Android Studio you have to write it in the code, so you have to write it yourself You have to be aware that "this is the XML that corresponds to this Java". Therefore, there are basically no rules for file naming, but the tacit understanding is that "Java and XML names correspond".
As usual, it's only kotlin operation from here, so thank you for saying "It's okay to write in Java". Actually, a Java file is created in a new project, so you have to rewrite it to kotlin.
If you open the Main Activity you created earlier from the navigation on the left, you will see the screen above. After confirming that Main Activity is selected on the tab, open the Code above and press "Convert Java File to Kotlin File" added at the bottom. Then a pop-up will appear and wait for a while.
The tab icon From When it changes like this, the conversion is complete. At the bottom right of the icon is a small K pattern, which is the kotlin logo. The extension has also changed from ".java" to ".kt". Please note that if you forget this operation, Kotlin will be written in the Java file and an error will occur. If you click with two fingers on the left navigation bar, the above screen will open. If you select "New", you can select the type of file to add. You can choose from various options, but basically you will use the third "kotlin Activity" from the top. If you select this, kotlin files and XML files will be added at the same time, which is relatively convenient.
Up to here for this time. Next, I will write about "Gradle", which is important for making Android.
Introduction to kotlin for iOS developers ①-Environment construction Introduction to kotlin for iOS developers ②-Project creation Introduction to kotlin for iOS developers ③-About gradle Introduction to kotlin for iOS developers ④-Type [Introduction to kotlin for iOS developers ⑤-Practical XML] (http://qiita.com/parappa1002/items/867c5b30055312e74fdb) [Introduction to kotlin for iOS developers ⑥-kotlin creation] (http://qiita.com/parappa1002/items/9f898feb4f83e672b384)
Recommended Posts