Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- til
- MySQL
- 인스턴스
- Kotlin
- return
- continue
- 개발자 번아웃
- VS Code
- 제어문
- 리액트
- 노개북
- vscode
- 노마드코더
- HTML
- Today I Learned
- 자바스크립트
- Java
- 개발자북클럽
- JavaScript
- JavaScript 이벤트
- CREATE
- 메서드
- break
- IT잡학사전
- If
- CSS
- 버전 표시 방법
- react
- while
- 이클립스 설치
Archives
- Today
- Total
윤제니
Android - Java 프로젝트에서 Kotlin 사용하기 본문
1. Java Project 생성
* Language => Java 선택 *
2. Android Studio -> Preferences -> Plugins -> "Kotlin" 검색 -> Install


3. build.gradle(Project) / build.gradle(Module)
- build.gradle(Project)

- build.gradle(Module)

4. Code
- activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi"
android:textAppearance="?android:attr/textAppearanceMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
- MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
TextView tvText;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvText = (TextView) findViewById(R.id.text);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.button) {
tvText.setText(HelloKt.formatMessage("Android with kotlin"));
}
}
}
- Hello.kt
fun formatMessage(name: String): String = "Hello, $name"
5. 실행화면


'Android' 카테고리의 다른 글
Linear Layout (0) | 2020.09.24 |
---|