不同SoftInputMode在同一个活动,这可能吗? [英] Different SoftInputMode in the same Activity, is it possible?

查看:201
本文介绍了不同SoftInputMode在同一个活动,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试键盘打开时设置我的片段的调整有所不同,但目前我在这里有没有积极results.enter code

I try to set the adjustment of my fragments differently when the keyboard opens, but for the moment I have no positive results.enter code here

目标将是只调整两个片段中的一个。

The objective would be to readjust only one of the two fragments.

下面是一个例子。

活动

public class MainActivity extends Activity {
...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.frame1, new PlaceholderFragment())
                    .commit();
            getFragmentManager().beginTransaction()
                    .add(R.id.frame2, new PlaceholderFragment1())
                    .commit();
        }
    }
...

片段:

public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
     //   Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.noresize);
     //   LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);


        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        return inflater.inflate(R.layout.fragment_main, container, false);

    }
}

public static class PlaceholderFragment1 extends Fragment {

    public PlaceholderFragment1() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        View rootView = inflater.inflate(R.layout.fragment_main_2, container, false);
        return rootView;
    }
} 

活动的主要布局:

main layout of the Activity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame"
    android:orientation="horizontal"
    >
<FrameLayout
        android:id="@+id/frame1"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent">
<FrameLayout
        android:id="@+id/frame2"
        android:background="#30000000"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent">

</LinearLayout>

OK看到我重新定义了两次SoftInputMode上的活动,这是不可能成功的。
因此,是否有可能做这样的事情fragment.getWindows.setSoftInputMode(...

ok saw that I redefined twice SoftInputMode on the activity, this is unlikely to succeed. so, is it possible to do something like that fragment.getWindows.setSoftInputMode (...

对不起,我的英语...

sorry for my english ...

推荐答案

都是您的片段在屏幕上在同一时间?如果是这样,不可能对具有不同的行为,这取决于片段触发软输入自设置以打开是一个适用于整个窗口仅

Are both your Fragments are on screen at the same time? If so it isn't possible to have different behavior depending on which Fragment triggered the soft input to open since the setting is a applicable to the whole window only.

在另一方面,如果你只需要在屏幕上这些片段的一次,则该方法 onCreateView()可能不是这个$ C $正确的地方C。你可能会想尝试把它在片段的方法 onResume()的onPause()。在 onResume()保存现有软输入模式,并将其设置为你想要的东西,并在的onPause()恢复的软输入模式,它是什么了。

On the other hand if you only have one of these Fragments on screen at a time then the method onCreateView() is probably not the right place for this code. You might want to try putting it in the Fragment methods onResume() and onPause(). In onResume() save the existing soft input mode and set it to what you want and in onPause() revert the soft input mode to what it was before.

这篇关于不同SoftInputMode在同一个活动,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆