android - 为 viewpager 中的 fragment 改变 windowSoftInputMode

标签 android

我有一个带有 2 个不同 fragment 的 ViewPager。 对于第一个 fragment ,我想对其进行定义,使其不会在软键盘打开时调整大小。 对于第二个 fragment ,我想让它调整大小。

在 list 中设置 android:windowSoftInputMode="adjustPan" 将适用于两个 fragment ,但我想在两者之间改变它。

谷歌搜索后我做了什么:

    // 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>

Activity 是使用默认的 windowSoftInputMode 定义的,当软键盘打开时会调整 View 的大小。

将一直在解决这个问题,直到它得到解决,但如果其他人有这个问题并解决了它,很高兴听到任何想法。

谢谢!

最佳答案

您可以在每个 onCreateView 上调用

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

检查 http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#SOFT_INPUT_ADJUST_RESIZE

在我的情况下,这并不能解决问题,因为我有一个透明的 Fragment(一个聊天窗口),我需要调整它的大小,而底部的 Fragment 不应该。但我认为它可能对你有用。

关于android - 为 viewpager 中的 fragment 改变 windowSoftInputMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16421857/

相关文章:

android - 如何在 Android 中更改 Edittext 颜色边框

android - MonoForAndroid : android-support-v4. jar编译问题

java - 为什么我无法删除项目?

android - android.permission.FLASHLIGHT有什么用?

Android TabLayout tabPaddingTop 和 tabPaddingBottom 未被删除

android - 如何增加 Logcat 中的行数(日志级别)

java - 对话框中的通用 onclick 监听器

android - 如何在 ArrayAdapter 中使用 DownloadManager

javascript - 使用 sendJavascript() Phonegap

android:在发送到服务或广播接收器的启动器中创建快捷方式