标签:android style blog http color java 使用 os
一 ,在string.xml 中添加字符串
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">EX_Ctrl_3</string> <string name="dear">亲爱的圣诞老人:</string> <string name="sendmyWish">送出愿望</string> <string name="yourWish">你的愿望:</string> <string name="hasSend">已送达圣诞老人信箱!</string> </resources>
二,在main.xml 布局中添加UI 元素:一个TextView、一个EditView 和一个Button
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/TextView_dear" android:text="@string/dear"></TextView> <EditText android:layout_height="wrap_content" android:id="@+id/EditText_Wish" android:layout_width="fill_parent"></EditText> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button_Send" android:text="@string/sendmyWish" android:layout_marginLeft="50px"></Button> </LinearLayout>
三,mainActivity.java 文件
1 package zyf.EX_Ctrl_3; 2 import android.app.Activity; 3 import android.os.Bundle; 4 import android.text.Editable; 5 import android.view.View; 6 import android.widget.Button; 7 import android.widget.EditText; 8 import android.widget.Toast; 9 public class EX_Ctrl_3 extends Activity { 10 /** Called when the activity is first created. */ 11 /*声明两个对象变量(按钮与编辑文字)*/ 12 private Button mButton; 13 private EditText mEditText; 14 @Override 15 public void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.main); 18 /*通过findViewById()取得对象*/ 19 mButton=(Button)findViewById(R.id.Button_Send); 20 mEditText=(EditText)findViewById(R.id.EditText_Wish); 21 /*设置onClickListener 给Button 对象聆听onClick 事件*/ 22 mButton.setOnClickListener(new Button.OnClickListener(){ 23 @Override 24 public void onClick(View v) { 25 // TODO Auto-generated method stub 26 /*声明字符串变量并取得用户输入的EditText 字符串*/ 27 Editable Str; 28 Str=mEditText.getText(); 29 /*使用CharSequence类getString()方法从XML中获取String*/ 30 CharSequence string2=getString(R.string.yourWish); 31 CharSequence string3=getString(R.string.hasSend); 32 /*使用系统标准的makeText()方式来产生Toast 信息*/ 33 Toast.makeText( EX_Ctrl_3.this,string2+Str.toString()+string3,Toast.LENGTH 34 _LONG).show(); 35 /*清空EditText*/ 36 mEditText.setText(""); 37 } 38 }); 39 } 40 }
标签:android style blog http color java 使用 os
原文地址:http://www.cnblogs.com/xiaoli3007/p/3890644.html