我有一个按钮以编程方式创建我需要同时实现onClick和OnTouch到该按钮我想要实现按钮focus_change
。
像这样实施
ImageView Settings_Button = new ImageView(this);
Settings_Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//UtilityClass.focusOnallviews(view);
Intent newIntent = new Intent(activity.getBaseContext(), ProfileSettingActivity.class);
activity.startActivity(newIntent);
}
});
Note
:当我与按钮交互时,我希望实现state_focused
和state_pressed
如何解决此问题。
答案 0 :(得分:1)
您可以使用OnTouch事件
ImageView Settings_Button = new ImageView(this);
Settings_Button.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch(arg1.getAction()){
case MotionEvent.ACTION_DOWN:
// Button is pressed. Change the button to pressed state here
break;
case MotionEvent.ACTION_MOVE:
// Button is being touched and swiped
break;
case MotionEvent.ACTION_UP:
// Button is released. Change the button to unpressed state here.
Intent newIntent = new Intent(activity.getBaseContext(),ProfileSettingActivity.class);
activity.startActivity(newIntent);
break;
}
});