Home  >  Article  >  Java  >  The perfect solution for Android development soft keyboard to block the login button

The perfect solution for Android development soft keyboard to block the login button

高洛峰
高洛峰Original
2017-01-07 11:39:361420browse

On the application login page we need to fill in the username and password. When filling in this information, the soft keyboard will block the login button, which makes the user experience poor, so we will solve this problem today

1: The login layout interface is as follows

<?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:background="@drawable/login_bg" > 
<LinearLayout 
android:id="@+id/ll_center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > 
<ScrollView 
android:id="@+id/sl_center"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fadingEdge="none"
android:scrollbars="none" > 
<RelativeLayout 
android:id="@+id/rl_center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > 
<LinearLayout 
android:id="@+id/sms_login_ll_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dip"
android:orientation="horizontal" > 
<ImageView 
android:id="@+id/sms_login_iv_icon"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_gravity="center_vertical"
android:src="@drawable/login_top_icon" /> 
<ImageView 
android:id="@+id/sms_login_iv_big_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dip"
android:src="@drawable/sms_login_icon_big" /> 
</LinearLayout> 
<ImageView 
android:id="@+id/sms_login_iv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sms_login_ll_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dip"
android:background="@drawable/sms_login_icon_small" /> 
<RelativeLayout 
android:id="@+id/sms_login_rl_input_name"
android:layout_width="fill_parent"
android:layout_height="43dip"
android:layout_below="@id/sms_login_iv_name"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:layout_marginTop="40dip"
android:background="@drawable/login_top_input" > 
<ImageView 
android:id="@+id/sms_login_iv_input_name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/login_input_icon_user" /> 
<FrameLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/sms_login_iv_input_name_icon" > 
<EditText 
android:id="@+id/sms_login_et_accout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_white"
android:digits="@string/sms_login_accout_text"
android:hint="请输入账号"
android:singleLine="true"
android:text=""
android:textSize="20sp" /> 
</FrameLayout> 
</RelativeLayout> 
<RelativeLayout 
android:id="@+id/sms_login_rl_input_pass"
android:layout_width="fill_parent"
android:layout_height="43dip"
android:layout_below="@id/sms_login_rl_input_name"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:background="@drawable/login_top_input" > 
<ImageView 
android:id="@+id/sms_login_iv_input_pass_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/login_input_icon_pwd" /> 
<FrameLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/sms_login_iv_input_pass_icon" > 
<EditText 
android:id="@+id/sms_login_et_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_white"
android:digits="@string/sms_et_change_password_old_text"
android:hint="请输入密码"
android:inputType="textPassword"
android:singleLine="true"
android:text=""
android:textSize="20sp" /> 
</FrameLayout> 
</RelativeLayout> 
</RelativeLayout> 
</ScrollView> 
<Button 
android:id="@+id/sms_login_bt_confirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/sms_login_rl_input_pass"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:layout_marginTop="16dip"
android:background="@drawable/sms_update_pass_bg_selector"
android:text="登 录"
android:textColor="@color/white"
android:textSize="20sp" /> 
</LinearLayout> 
</RelativeLayout>

Things to note Yes:

1: Hierarchical relationship

RelativeLayout-----

LinearLayout----

ScrollView,

Button

2: Configure the activity in AndroidManifest.xml Android:windowSoftInputMode="stateHidden|adjustResize"

3: Look at the following code

etAccount = (EditText) this.findViewById(R.id.sms_login_et_accout); 
etAccount.setOnClickListener(this); 
etAccount.setOnTouchListener(new OnTouchListener() { 
@Override
public boolean onTouch(View v, MotionEvent event) { 
changeScrollView(); 
return false; 
} 
}); 
/** 
* 使ScrollView指向底部 
*/
private void changeScrollView(){ 
h.postDelayed(new Runnable() { 
@Override
public void run() { 
sl_center.scrollTo(0, sl_center.getHeight()); 
} 
}, 300); 
} 
Handler h = new Handler(){ 
public void handleMessage(Message msg) { 
}; 
};

The above is the editor I would like to introduce to you the perfect solution for Android development soft keyboard to block the login button. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more related articles on the perfect solution for Android development soft keyboard to block the login button, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn