我有一个包含2个不同片段的ViewPager。 对于第一个片段,我想定义它,以便它不会在软键盘打开时调整大小。 对于第二个片段,我想重新调整大小。
在清单中设置android:windowSoftInputMode="adjustPan"
对两个片段都有效,但我想在两者之间改变它。
谷歌搜索后我做了什么:
// create ContextThemeWrapper from the original Activity Context with the custom theme
Context context = new ContextThemeWrapper(getActivity(), R.style.NoResize);
// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(context);
// inflate using the cloned inflater, not the passed in default
return localInflater.inflate.inflate(R.layout.my_layout,container,false);
我自定义了主题:
<style name="NoResize" parent="@style/AppTheme">
<item name="android:windowSoftInputMode">adjustPan</item>
</style>
活动是使用默认的windowSoftInputMode定义的,它会在软键盘打开时调整视图的大小。
将会解决这个问题直到它得到解决,但如果其他人有这个问题并解决了它,那么听到任何想法都会很棒。
谢谢!
答案 0 :(得分:73)
您可以调用每个onCreateView
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
在我的情况下,这并没有解决问题,因为我有一个透明的片段(聊天窗口),我需要调整大小,底部的片段不应该。但我认为这对你有用。