public void hideSearchBar(boolean shiftView) { if (shiftView) { mSearchViewContainer.animate().cancel(); mSearchViewContainer.setAlpha(1); mSearchViewContainer.setTranslationY(0); mSearchViewContainer .animate() .withLayer() .alpha(0) .translationY(-mSearchView.getHeight()) .setDuration(200) .setListener(mHideListener); mFragmentsFrame .animate() .withLayer() .translationY(-mSearchViewContainer.getHeight()) .setDuration(200) .setListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBottomPaddingView.setVisibility(View.VISIBLE); mFragmentsFrame.setTranslationY(0); mActionBar.setVisibility(View.INVISIBLE); } }); } else { mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); mActionBar.setVisibility(View.INVISIBLE); } }
@Override public boolean dispatchTouchEvent(MotionEvent event) { // BUG #57535 // 【发帖】发帖页面键盘弹出后,如果这时点击手机的HOME键、电源键或其他输入键盘上手机自带按钮进入其他页面,再返回到发帖页面,输入键盘会隐藏,小键盘按钮会高亮显示 if (isOpenComment) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int[] l = {0, 0}; mEditContent.getLocationInWindow(l); int left = l[0], top = l[1]; int bottom = top + mEditContent.getHeight(), right = left + mEditContent.getWidth(); System.out.println( "left:" + left + "; top:" + top + ";bottom:" + bottom + ";right:" + right); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { mInputBar.showCommonInputBar(); // return false; } else { InputMethodUtils.collapseSoftInputMethod(mContext, mEditContent.getWindowToken()); // return true; } } } return super.dispatchTouchEvent(event); }
@Test public void testPropsApplied() { UIManagerModule uiManager = getUIManagerModule(); ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application); int rootTag = uiManager.addMeasuredRootView(rootView); int textInputTag = rootTag + 1; final String hintStr = "placeholder text"; uiManager.createView( textInputTag, ReactTextInputManager.REACT_CLASS, rootTag, SimpleMap.of(ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr)); uiManager.manageChildren( rootTag, null, null, SimpleArray.of(textInputTag), SimpleArray.of(0), null); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); EditText editText = (EditText) rootView.getChildAt(0); assertThat(editText.getHint()).isEqualTo(hintStr); assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37)); assertThat(editText.getHeight()).isEqualTo(20); }
/** * 隐藏软键盘 时判断输入框的位置 * * @param v * @param event * @return */ public static boolean isShouldHideInput(View v, MotionEvent event, EditText ed) { if (v != null && (v instanceof EditText)) { int[] leftTop = {0, 0}; // 获取输入框当前的location位置 ed.getLocationInWindow(leftTop); int left = leftTop[0]; int top = leftTop[1]; int bottom = top + ed.getHeight(); int right = left + ed.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // 点击的是输入框区域,保留点击EditText的事件 return false; } else { return true; } } return false; }