You are on page 1of 5
9 ie GS otercode 1 ded role mat ES Brame 1 | @@ sn (8 gen [Generated Jave Fie] |B mh aod be avec 8 ves Be drowelle ce > layout i vias GF AndroldManitest xt ED dsfaue-propertias & saneic 2) Todos & @B tooo Hello World, BgaH Example 1 ! 2 ‘le! ng> Ent fork here B6:Trong thu myc values, tao file colors.xmI(@hudt phai vao thu myc, chon New - > Android XML File, va luru ¥ chit s, khé color.xml). Gé ndi dung cho file nhur sau: Ma: #££3300 OK, vay la ban da tao méi cho ding chit sé duge hién thj trong Text View (£13300 1a ma mau dé). Thye chat ban hoan toan c6 thé go thing Ma: android:t! t€olbr="#££3300" trong file mai nxt ma khéng cn tao méi file colors.xml, nhung mye dich ciia XML trong Android chinh la dé hé trg nang cp chinh stra dé dang. Néu sau nay ban muén sita mau cita dong text thi chi can vao colors.xml thay déi thay vi mo mam trong main.xml (c6 thé rat dai néu giao dién phic tap). Cc thanh phan trén méi chi la cdc phan co ban cla XML. Ngoai ra cdc ban co thé khai bao thém vé Animation, Style va Theme (phic tap hon nhiéu nén minh khéng gidi thigu trong phan co ban nay). BZ: Vay la ching ta di hoan thién phan giao dién voi XML, gid dén viét code dé xir ly cdc su kign cho céc thanh p => vio thu muc sre (source code cla project) => at.exam => Example,java, g6 noi dung code sau vio: Ma: Ce package at.exam; WE imp android.app.Activity; © import android.os.Bundle; import android.view.KeyEve SS android. view.View; android. view.View.OnKeyListeser; import impor android.widget .EditText android.widget .TextVi impor impor: public class Example exte étivity { /** Called when the ee ty is first created. */ @override public void onCr ndle savedInstanceState) { super.onCr //Thiét giao dién ldy ti file main.xml setcongentiziew (R. layout main) ; //Laylwé>cac thanh phan trong main.xml théng edit = qua id soa ditText findViewByTa{R. id.edit_t final TextView findViewByld(R.id.text_ (EditText) (TextView) //Thiét lap xi ly cho sy kién nh4n ntt gita cta dién thoai edit.setOnKeyListener(new OnKeyListener() { @override public boolean onkey(View v, int keyCode, KeyEvent event) { if (event.getAction() -- KeyEvent .ACTION_DOWN && keyCode KeyEvent.KEYCODE_DPAD_CENTER) { text.setText (edit. getText ().toString()); edit.setText (""); return true; be | © return false;

You might also like