EditText:
<EditText
android:id="@+id/extension"
android:layout_width="@dimen/login_extension_width"
android:layout_height="@dimen/login_enter_text_height"
android:layout_below="@+id/extension_label"
android:layout_marginLeft="@dimen/login_margin"
android:layout_toRightOf="@+id/phone"
android:background="@drawable/login_screen_edit_shape"
android:hint="@string/extension_hint"
<strong>android:inputType="phone|numberDecimal" //这样只能输入数字</strong>
android:maxLength="5"
<strong>android:nextFocusDown="@+id/password" //键盘点击next可以跳转下一个</strong>
android:paddingLeft="@dimen/login_label_padding_left"
android:singleLine="true"
android:textColor="@color/login_text"
android:textColorHint="@color/login_hint"
android:textSize="@dimen/login_edit_text_size" />
点击done可以进行一些操作:
passwordField.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (<strong>keyCode == KeyEvent.KEYCODE_ENTER</strong>) {
mLoginBtn.performClick();
return true;
}
return false;
}
});
这样来写Layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f4f4f4"
android:scrollbars="none" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f4f4f4"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="email:"
android:textColor="#484848"
android:textSize="20sp" />
<AutoCompleteTextView
android:id="@+id/etEmailAddr"
android:maxLength="64"
android:singleLine="true"
android:layout_below="@id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:inputType="textEmailAddress"
android:imeOptions="actionNext" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/etEmailAddr"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="password"
android:textColor="#484848"
android:textSize="20sp" />
<EditText
android:id="@+id/etPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/TextView02"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:hint="input password" >
</EditText>
<Button
android:id="@+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/etPwd"
android:layout_centerInParent="true"
android:layout_marginTop="50dp"
android:background="@drawable/button_item_selector"
android:text="Stop"
android:textColor="#fff"
android:textSize="17sp" >
</Button>
<Chronometer
android:id="@+id/duration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btSend"
android:layout_centerVertical="true"
android:layout_marginLeft="17dp"
android:layout_marginRight="17dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="bold"
android:typeface="normal"
>
</Chronometer>
</RelativeLayout>
</LinearLayout>
</ScrollView>
代码:
mEtEmail = (AutoCompleteTextView) findViewById(R.id.etEmailAddr);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.email_addrs_list));
mEtEmail.setAdapter(adapter);
final Chronometer mCallDuration = (Chronometer)findViewById(R.id.duration);
mCallDuration.setBase(SystemClock.elapsedRealtime());
mCallDuration.setFormat("Formatted time (%s)");
mCallDuration.start();
Button btn = (Button)findViewById(R.id.btSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallDuration.stop();
}
});
图: