Android onfocus不适用于按钮
我查过了。它起作用了。请注意,在Emulator上,当您通过滚动上/下箭头转到按钮时,会发生onFocus 我有以下代码:Android onfocus不适用于按钮,android,Android,我查过了。它起作用了。请注意,在Emulator上,当您通过滚动上/下箭头转到按钮时,会发生onFocus 我有以下代码: final View b= (Button) findViewById(R.id.find); b.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean
final View b= (Button) findViewById(R.id.find);
b.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus==true)
{
Toast.makeText(user_interface.this, "onfocus", Toast.LENGTH_LONG).show();
// b.setBackgroundColor(R.color.gray);
}
else
{
Toast.makeText(user_interface.this, "lossfocus", Toast.LENGTH_LONG).show();
}
}
});
对于按钮,您为什么使用:
最终视图???也许这就是问题所在
使用按钮b=(按钮)findViewById(R.id.find) 他使用final是因为如果不使用final,他可能会出现编译错误,因为在匿名类中使用final。thanx,是的,使用up/down键可以工作,为什么它不能在手机上使用mouseon focus,这正好意味着焦点(光标)在字段上。在onFocus中未检测到鼠标光标。事实上,根本无法检测到鼠标光标。我使用此方法,但不适用于我我希望单击时显示进度条,不可见此按钮不起作用请指导我,即使在手机上单击时不显示,这是我的codelogin.setOnFocusChangeListener((v,hasFocus)->{login.setFocusableInTouchMode(true);if(!hasFocus){login.setVisibility(View.INVISIBLE);bar.setVisibility(View.VISIBLE);loginBinding.userNameEt.setClickable(false);Toast.makeText(此“非焦点”,Toast.LENGTH_SHORT)。show();loginBinding.userPasswordEt.setClickable(false);}else Toast.makeText(这个“焦点”,Toast.LENGTH_SHORT.show();});
btnSign.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
//Toast line...
}
}
});