码迷,mamicode.com
首页 > 移动开发 > 详细

仿苹果锁屏实现

时间:2014-09-16 23:44:11      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:苹果   锁屏   


 

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>



 

仿苹果锁屏实现

标签:苹果   锁屏   

原文地址:http://blog.csdn.net/jgszhuzhu/article/details/39325669

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!