diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 89388b2c95..dc13ee6b07 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -536,6 +536,11 @@ bool TextField::onTouchBegan(Touch *touch, Event *unusedEvent) bool pass = Widget::onTouchBegan(touch, unusedEvent); if (_hitted) { + if (isFocusEnabled()) + { + requestFocus(); + } + _textFieldRenderer->attachWithIME(); } else diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index 3a1accbad6..c81cc8d98d 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -888,6 +888,12 @@ void Widget::moveEvent() void Widget::releaseUpEvent() { this->retain(); + + if (isFocusEnabled()) + { + requestFocus(); + } + if (_touchEventCallback) { _touchEventCallback(this, TouchEventType::ENDED); @@ -1449,7 +1455,7 @@ void Widget::onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus) } } -Widget* Widget::getCurrentFocusedWidget()const +Widget* Widget::getCurrentFocusedWidget() { return _focusedWidget; } diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 8ba4236d7e..964dce5f2e 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -775,7 +775,7 @@ public: * Return a current focused widget in your UI scene. * No matter what widget object you call this method on , it will return you the exact one focused widget. */ - Widget* getCurrentFocusedWidget()const; + static Widget* getCurrentFocusedWidget(); /* * Call this method with parameter true to enable the Android Dpad focus navigation feature