Android
오늘부터 안드로이드를 배우기 시작했다.
Oracle 때도 그랬지만 새로운 걸 배울 때는 항상 뭔가 설렌다.
물론 동작 확인을 할 때 시간이 오래 걸려 설레는 마음이 금방 사그라들긴 했지만 :(
안드로이드에 대한 기초 배경지식을 듣고
Button, TextView, EditText를 사용해봤다.
- view : 앱 실행 화면을 구성하는 요소
- 안드로이드 화면에서 실제로 사용되는 것들은 모두 View 클래스의 상속을 받음
- 뷰 클래스를 위젯이라고도 함(Button, TextView, EditText, RadioButton ...)
- layout : 다른 위젯을 담을 수 있는 위젯. 위젯을 포함하는 컨테이너 역할
- 보이는 화면(view)에 대한 코드는 xml에 작성함
- 안드로이드 개발 언어는 Java, Kotlin이 있음
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="버튼1"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="10dp"
android:backgroundTint="#228811"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="이건 텍스트뷰입니다."
android:padding="20dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="이건 에디트텍스트입니다"
android:background="#001177"
android:textColor="#ffffff"
android:layout_margin="20dp"
android:textSize="13dp"
android:padding="2dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="버튼2"
android:backgroundTint="#EBF5FB"
android:textColor="#AEB6BF"
android:layout_margin="20dp"/>
</LinearLayout>
- text size / color / style, typeface, singleline, id 속성 연습
<?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"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text size 속성"
android:textSize="30dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text color 속성"
android:textSize="30dp"
android:textColor="#55ff99"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text style 속성"
android:textSize="30dp"
android:textStyle="italic|bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="typeface 속성"
android:textSize="30dp"
android:typeface="monospace"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="singleline singleline singleline singleline"
android:textSize="30dp"
android:maxLines="1"
android:ellipsize="end"
/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btnClick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="click"
/>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // resource.layout.activity_main
TextView tv = findViewById(R.id.textView);
tv.setText("그냥 텍스트뷰 그냥 텍스트뷰 그냥 텍스트뷰");
tv.setTextColor(0xffff0000);
tv.setTypeface(Typeface.SERIF);
tv.setMaxLines(1);
Button btnClick = findViewById(R.id.btnClick); // alt + enter : import Class
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("mytag", "click"); // System.out.println(); // tag: Logcat에서 원하는 메시지만 검색해서 보기 위한 키워드
}
});
}
}