文本框作为最简单也是使用最平凡的控件,也说说吧。
来吧,少年,来添加Activity,src文件夹下添加一个EditTextActivity。
View Code package cn.Kurodo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.util.Log; public class EditTextActivity extends Activity { private Button m_button; private EditText m_editText; public EditTextActivity() { // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super .onCreate(savedInstanceState); setContentView(R.layout.edittext); m_button = (Button)findViewById(R.id.editBtn); m_editText = (EditText)findViewById(R.id.editText); m_editText.selectAll(); m_button.setOnClickListener( new ButtonListener()); } class ButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.v( " EditText " , m_editText.getText().toString()); } }}
EditText的布局文件
View Code <? 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" > < EditText android:id ="@+id/editText" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/edittext" /> < Button android:id ="@+id/editBtn" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/editBtn" /> </ LinearLayout >
运行效果如下:
转载于:https://www.cnblogs.com/Kurodo/archive/2011/08/04/2126795.html
相关资源:Android定制控件:带图标有颜色TextView、可编辑文本框|附项目结构图和效果图