首页 > 代码库 > 仿苹果锁屏实现
仿苹果锁屏实现
public class LockActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.lockscreen); initUI(); } public EditText editText,editText2,editText3,editText4; private void initUI(){ editText = (EditText) findViewById(R.id.editText1); editText2 = (EditText) findViewById(R.id.editText2); editText3 = (EditText) findViewById(R.id.editText3); editText4 = (EditText) findViewById(R.id.editText4); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub String resString =editText.getText().toString().trim(); if (resString!=null && resString.length()>0) { editText2.requestFocus(); } } }); editText2.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub String resString =editText2.getText().toString().trim(); if (resString!=null && resString.length()>0) { editText3.requestFocus(); } } }); editText3.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub String resString =editText3.getText().toString().trim(); if (resString!=null && resString.length()>0) { editText4.requestFocus(); } } }); editText4.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub String resString =editText4.getText().toString().trim(); if (resString!=null && resString.length()>0) { //隐藏键盘 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText4.getWindowToken(), 0); //强制隐藏键盘 } } }); } }
布局如下:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="20dp"> <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_height="wrap_content" android:singleLine="true" android:ems="1" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_height="wrap_content" android:singleLine="true" android:ems="1" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/editText3" android:layout_width="fill_parent" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_height="wrap_content" android:singleLine="true" android:ems="1" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/editText4" android:layout_width="fill_parent" android:layout_weight="1" android:layout_marginLeft="20dp" android:layout_height="wrap_content" android:singleLine="true" android:ems="1" android:inputType="textPassword" > </EditText> </LinearLayout></RelativeLayout>
仿苹果锁屏实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。