¾È±Ô °øºÎ¹æ

Android > ¹öÆ°(Button), À̹ÌÁö ¹öÆ°(ImageButton) À̶õ ¹«¾ùÀΰ¡?

µî·ÏÀÏ : 2017-07-06 17:12 Á¶È¸¼ö : 53,227

¾Èµå·ÎÀ̵åÀÇ À¯Àú ÀÎÅÍÆäÀ̽º Áß »ç¿ëÀÚÀÇ ¼±Åà ȮÀÎ µî¿¡ »ç¿ëµÇ´Â ¿ä¼ÒÀÔ´Ï´Ù.

¾Èµå·ÎÀÌµå ¹öÆ° (Android Button) »ó¼Ó °èÃþµµ
 

		java.lang.Object
		¦¦¦¡ android.view.View
			¦¦¦¡android.widget.TextView
				¦¦¦¡ android.widget.Button
	


¹öÆ°ÀÇ ÇÏÀ§ Ŭ·¡½ºµé : CompoundButton, CheckBox, Chronometer, DigitalClock, EditText

ButtonÀº »ç¿ëÀÚ°¡ ´©¸¦¼ö ÀÖ´Â ÇüÅÂÀÇ À§Á¬ÀÔ´Ï´Ù. ´©¸£°í Àְųª(press), Ŭ¸¯Çϰųª µîÀÇ ÇൿÀ» ÇÒ¼ö ÀÖ´Â ³à¼®ÀÌÁÒ.

1. xml·Î Button ¸¸µé±â

TestButtonActivity.java

		public class TestButtonActivity extends Activity {
			/** Called when the activity is first created. */
			@Override
			public void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				setContentView(R.layout.main);

				Button btn01 = (Button)findViewById(R.id.button1);
			}
		}
		


activity_main.xml

		<?xml version="1.0" encoding="utf-8"?>
		<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:orientation="vertical" >
			
			<Button
				android:id="@+id/button1"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:text="¹öÆ°1¹ø" 
				android:textColor="#FF0000"/>
		</LinearLayout>
		


¸¸µå´Â ¹æ¹ýÀº À§Ã³·³ °£´ÜÇÕ´Ï´Ù.

2. ÀÚ¹ÙÄڵ忡¼­ ¾Èµå·ÎÀÌµå ¹öÆ° ¸¸µé±â

¾Æ·¡ ¼Ò½º´Â ÀÚ¹Ù¼Ò½º»ó¿¡¼­ ¹öÆ°À» ¸¸µé¾î ¼Ó¼ºÀ» Àû¿ëÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù.

TestButtonActivity.java

		public class TestButtonActivity extends Activity {
			/** Called when the activity is first created. */

			@Override
			public void onCreate(Bundle savedInstanceState) {
				super.onCreate(savedInstanceState);
				setContentView(R.layout.main);

				Button btn02 = new Button(this);
				btn02.setText("ÀÚ¹ÙÄÚµå·Î ¹öÆ° ¸¸µé±â");
				btn02.setTextColor(0xFFFF00);
				btn02.setTextSize(30);
			}
		}
		


new Button() °´Ã¼¸¦ »ý¼ºÇؼ­ ¸¸µé¾î ÁÙ ¼ö ÀÖ½À´Ï´Ù.

3. À̹ÌÁö ¹öÆ° ¿¹Á¦(XML)

À̹ÌÁö ¹öÆ°ÀÇ À̹ÌÁö¸¦ ¼³Á¤ÇÏ´Â °ÍÀº “android:src” ¼Ó¼ºÀ» ÀÌ¿ëÇØ¾ß ÇÕ´Ï´Ù.
 

		<ImageButton
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:src="@drawable/button_icon"/>
		


4. ÀÏ¹Ý Button ¿¡ À̹ÌÁö Ãß°¡(XML)

Button µµ TextView ó·³ »óÇÏÁ¿쿡 À̹ÌÁö Çϳª¸¦ »ðÀÔÇÒ ¼ö ÀÖ½À´Ï´Ù.
 

		<Button
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="@string/button_text"
			android:drawableLeft="@drawable/button_icon" />


 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.