0
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();
}
}
});
他使用了final,否则由于anonymous类中的用法,他会得到编译错误。 – Geo 2011-03-25 08:48:11
thanx,是这个工作与上/下键为什么它不适用于鼠标 – 2011-03-29 04:59:41
焦点上的手机意味着焦点(光标)是在该字段上。在onFocus中未检测到鼠标光标。事实上,鼠标光标根本无法被检测到。 – 2011-03-29 08:30:56