在我的应用程序中,我有3个EditText
我遇到focus
问题,我希望清除EditText
的焦点,当用户点击我使用的提交按钮时,该焦点会成为焦点{ {1}}如果我在布局中使用单edittext.clearFocus()
,这样可以正常工作,如何清除多个EditText
的焦点请帮助
答案 0 :(得分:3)
在提交按钮上单击我尝试将其作为Roshan Jha建议并且效果很好
yourEditText.setFocusable(false);
yourEditText.setFocusableInTouchMode(true);
yourEditText1.setFocusable(false);
yourEditText1.setFocusableInTouchMode(true);
yourEditText2.setFocusable(false);
yourEditText2.setFocusableInTouchMode(true);
答案 1 :(得分:1)
只需在按下按钮时使用此功能......
当您单击提交按钮时,焦点将从所有editText
中丢失yourEditText.setFocusable(false);
yourEditText.setFocusableInTouchMode(false);
yourEditText1.setFocusable(false);
yourEditText1.setFocusableInTouchMode(false);
yourEditText2.setFocusable(false);
yourEditText2.setFocusableInTouchMode(false);
在点击侦听器
之后,最后在页面的最后一页使用此功能public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
yourEditText.setFocusable(true);
yourEditText.setFocusableInTouchMode(true);
}
return false;
}
再次更新
public class ChangePassword extends Activity implements OnClickListener
{
TextView txtUsername, txtCancel;
Button txtSubmit, btnback;
EditText txtOldPassword, txtNewPassword, txtConfirmPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.change_password);
txtOldPassword = (EditText) findViewById(R.id.txt_current_password);
txtOldPassword.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
txtOldPassword.setFocusable(true);
txtOldPassword.requestFocus();
}
});
txtNewPassword = (EditText) findViewById(R.id.txt_new_password);
txtNewPassword.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
txtNewPassword.setFocusable(true);
txtNewPassword.requestFocus();
}
});
txtConfirmPassword = (EditText) findViewById(R.id.txt_confirm_password);
txtConfirmPassword.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
txtConfirmPassword.setFocusable(true);
txtConfirmPassword.requestFocus();
}
});
txtSubmit = (Button) findViewById(R.id.txtsubmit);
btnback = (Button) findViewById(R.id.btnBack);
txtUsername = (TextView) findViewById(R.id.tv_login_name);
txtCancel = (TextView) findViewById(R.id.txtcancel);
txtSubmit.setOnClickListener(this);
txtCancel.setOnClickListener(this);
}
public void onClick(View view) {
switch(view.getId())
{
case R.id.txtsubmit:
txtOldPassword.setFocusable(false);
txtNewPassword.setFocusable(false);
txtConfirmPassword.setFocusable(false);
break;
case R.id.txtcancel:
finish();
break;
case R.id.btnBack:
finish();
break;
}
}
}
您的XML
<EditText
android:id="@+id/txt_current_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="6dp"
android:background="@drawable/backwithborder"
android:hint="@string/hint_current_password"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#b8b8b8"
android:textSize="17sp"
android:typeface="sans" >
答案 2 :(得分:0)
试试这个
editText.setFocusable(true / false);
答案 3 :(得分:0)
getWindow().getDecorView().clearFocus();
只是添加..你的布局应该有:
android:focusable="true"
android:focusableInTouchMode="true"