Dev/Android
Android Studio (프로젝트 새로 생성, 패키지명, save location, dependencies 변경, 디자인, 스플릿창, 테마 변경)
Walker_
2024. 4. 11. 17:03
1. 프로젝트 새로 생성
- 패키지명 : 유일한 이름으로 지정.
- 패키지명 중복되면 어플 등록 시 등록 안됨.
- save location : 경로 내에 한글, 공백 없도록 할 것
2. dependencies 변경
- 오류 떴을 시, build gradle(Module)파일 에서 dependencies를 맨 아래 이미지와 같이 수정 후 sync now 클릭
3. XML
- 디자인 창
- 스플릿 창 (주로 이 화면을 사용)
android:orientation="vertical"
- LinearLayout으로 수정 후 > orientation 추가
package kr.jeongmo.helloandroid
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn:Button = findViewById(R.id.button)
btn.setOnClickListener {
Toast.makeText(applicationContext, "!!", Toast.LENGTH_SHORT).show()
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
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="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Switch"
tools:layout_editor_absoluteX="103dp"
tools:layout_editor_absoluteY="123dp" />
</LinearLayout>
- Manifest에서 테마 변경
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.jeongmo.helloandroid">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
공부 과정을 정리한 것이라 내용이 부족할 수 있습니다.
부족한 내용은 추가 자료들로 보충해주시면 좋을 것 같습니다.
읽어주셔서 감사합니다 :)