티스토리 뷰
FullScreenMode에서 키보드 활성 시 버튼 위치 변경 - SOFT_INPUT_ADJUST_RESIZE
Dexx 2015. 10. 13. 17:37FullScreenMode에서 SoftKeyboard 활성 시 버튼의 위치를 키패드 위로 변경하고 싶은데 일반적인 방법으로는 지원되지 않음.
기본적인 방법으로는
1. Manifest 에서 activity 안에
android:windowSoftInputMode="stateHidden|adjustResize" (또는 adjustPan)
2. 자바 코드에서
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
SOFT_INPUT_ADJUST_PAN (Input영역 밀어 올리기)
SOFT_INPUT_ADJUST_RESIZE (UI 리사이징)
위 방법으로 해 봤지만 적용되지 않아 검색해 본 결과
안드로이드 자체에서 FullScreenMode일 때에는 지원하지 않는 것으로 보임
별도의 클래스를 만들어 간단히 해결하는 방법을 찾아 냄.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | public class AndroidBug5497Workaround { // For more information, see https://code.google.com/p/android/issues/detail?id=5497 // To use this class, simply invoke assistActivity() on an Activity that already has its content view set. public static void assistActivity (Activity activity) { new AndroidBug5497Workaround(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private AndroidBug5497Workaround(Activity activity) { FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard/4)) { // keyboard probably just became visible frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } else { // keyboard probably just became hidden frameLayoutParams.height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); return (r.bottom - r.top); } } | cs |
적용할 클래스에
1 | AndroidBug5497Workaround.assistActivity(this); | cs |
넣으면 간단히 해결!!!
참고 URL
'Android 개발 메모' 카테고리의 다른 글
EditText 상태 체크 - addTextChangedListener (0) | 2015.10.14 |
---|---|
Intent.ACTION_SEND 이미지 공유 하기 (0) | 2015.10.09 |
ViewPager 사용 시 ArrayList 데이터 전달 (0) | 2015.10.09 |
댓글