本文共 974 字,大约阅读时间需要 3 分钟。
EditText 是输入框
inputType可以来设置输入框允许输入的文字类型,如数字,邮箱,姓名等
android:singleLine="true" 可以设置不允许EditText变成多行
一个单行的数字输入框
<EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:inputType=""> </EditText>
判断内容是否是空
if (TextUtils.isEmpty(tx.getText())) { Toast.makeText(this, "TextView为空", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, tx.getText(), Toast.LENGTH_SHORT).show(); }
android.text.TextUtils 提供了一些列文字处理的方法
返回键
按返回键时调用onBackPressed方法.
下面重写该方法,实现只有双击返回键才能退出
@Override public void onBackPressed() { if (lastClickTime <= 0) { Toast.makeText(this, "双击退出应用", Toast.LENGTH_SHORT).show(); lastClickTime = System.currentTimeMillis(); } else { if (System.currentTimeMillis() - lastClickTime <= 1000) { // super.onBackPressed(); finish(); } else { Toast.makeText(this, "双击退出应用", Toast.LENGTH_SHORT).show(); lastClickTime = System.currentTimeMillis(); } } }
转载地址:http://tkffb.baihongyu.com/