TextView & Button & EditText

TextView
java.lang.Object
    android.view.View
        android.widget.TextView
텍스트뷰의 속성
text
textColor
textSize
typeface(글꼴 sherif, ...)
textStyle(글자 스타일 bold, italic, …)
singleLine(한 줄로 문자열 출력, 끝나면 … 으로 생략)
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="About Size" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:textColor="#00ff00"
android:text="About Color" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:textStyle="bold"
android:text="About Style" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:typeface="serif"
android:text="About Typeface" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:singleLine="true"
android:text="About Singleline" />
XML 속성을 Java 코드로 설정
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv3" />
MainActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Textview v1, v2, v3;
v1=(TextView)findViewById(R.id.tv1);
v2=(TextView)findViewById(R.id.tv2);
v3=(TextView)findViewById(R.id.tv3);
v1.setText("Hello");
v1.setTextColor(Color.RED);
v2.setTextSize(30);
v2.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC);
v3.setText("HELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLOHELLO");
v3.setSingleLine(true);
}
XML 속성 관련 메소드(java) 비고
background setBackgroundColor() View 클래스
clickable setClickable() View 클래스
cfocusable setFocusable() View 클래스
id setId() View 클래스
longClickable setLongClickable() View 클래스
padding setPadding() View 클래스
ratation setRotation() View 클래스
scaleX, scaleY setScaleX(), setScaleY() View 클래스
visibility setVisibility() View 클래스
gravity setGravity() View 클래스
inputType setRawInputType() TextView 클래스
password setTransformationMethod() TextView 클래스
text setText() TextView 클래스
textColor setTextColor() TextView 클래스
textSize setTextSize() TextView 클래스
Button
java.lang.Object
    android.view.View
        android.widget.TextView
            android.widget.Button
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="confirm" />
버튼 클릭했을 때 동작하는 Java 코드 3단계
1. 버튼 변수 선언
Button=button1;
2. 변수에 버튼 위젯 대입
button1=(Button) findViewById(R.id.bt1);        // bt1 from XML
3. 버튼을 클릭했을 때 동작하는 클래스 정의
button1.setOnClickListener(new View.OnClickListener(){
  public void onClick(View v){
  // click activity
  }
});
EditText
java.lang.Object
    android.view.View
        android.widget.TextView
            android.widget.EditText
<EditText
android:id="@+id/edittext1" />
에디트 텍스트의 값을 가져오는 Java코드 3단계
1. 에디트 텍스트 변수 선언
EditText et1;
2. 변수에 에디트 텍스트 위젯 대입
et1=(EditText)findViewById(R.id.edittext1)
3. 에디트 텍스트에 입력된 값 가져오기 ->주로 버튼 클릭 이벤트 리스너 안에 삽입
String ms;
ms=et1.getText().toString();