In my activity, ShowcaseView will appear, which will add to the decor view ((ViewGroup) activity.getWindow().getDecorView()).addView(mShowcaseView);
, and I want to define a key event to handle something, so I redefine dispatchKeyEvent()it to do what I need. but it looks like the method dispatchKeyEvent()has never been called, which is worse, PhoneWindow.DecorView#dispatchKeyEvent()not called, I donβt know why, please help me.
Thanks:).
here is my short ShowcaseViewsource code.
public class ShowcaseView extends FrameLayout {
public ShowcaseView(Context context) {
super(context);
init(context);
}
public ShowcaseView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ShowcaseView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
setWillNotDraw(false);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
setFocusable(true);
setEnabled(true);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
Log.d("Showcase", "dispatchKeyEvent: called");
super.dispatchKeyEvent(event);
return executeKeyEvent(event);
}
private boolean executeKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP
&& event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
hide();
}
return true;
}
}
source
share