首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KeyBoard隐藏EditText

KeyBoard隐藏EditText
EN

Stack Overflow用户
提问于 2016-03-11 17:31:03
回答 4查看 787关注 0票数 1
代码语言:javascript
复制
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

      InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);

    @Override
        public void onResume() {
            super.onResume();
            mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    mView.getWindowVisibleDisplayFrame(r);
                    int heightDiff = mView.getRootView().getHeight() - (r.bottom - r.top);

                    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                        //ok now we know the keyboard is up...
                        mView.findViewById(R.id.txt_error_message).setVisibility(View.GONE);
                        mView.findViewById(R.id.btn_user_signup).setVisibility(View.GONE);
                    } else {
                        //ok now we know the keyboard is down...
                        mView.findViewById(R.id.txt_error_message).setVisibility(View.VISIBLE);
                        mView.findViewById(R.id.btn_user_signup).setVisibility(View.VISIBLE);

                    }
                }
            });

        }


< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frag_cont_registration"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical"
    tools:context="com.apps.robo.fragments.FragmentItcRegistration">

    <EditText
        android:id="@+id/input_phone_email"
        android:layout_width="218dp"
        android:layout_height="45dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="36dp"
        android:background="@drawable/edit_text_border_bottom"
        android:fontFamily="@string/light_roboto"
        android:gravity="bottom|center"
        android:hint="@string/hint_enter_phone_number"
        android:inputType="number"
        android:maxLines="1"
        android:textColor="@android:color/white"
        android:textColorHint="@android:color/white"
        android:textSize="14sp"
        android:cursorVisible="true"/>
    <!-- android:singleLine="true" -->

    <TextView
        android:id="@+id/txt_error_message"
        android:layout_width="match_parent"
        android:layout_height="38dp"
        android:layout_gravity="center"
        android:fontFamily="@string/light_roboto"
        android:gravity="center"
        android:text="@string/enter_email"
        android:textColor="@android:color/white"
        android:textSize="15sp"
        android:visibility="gone" />


    <Button
        android:id="@+id/btn_user_signup"
        android:layout_width="218dp"
        android:layout_height="38dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="24sp"
        android:background="@drawable/bg_buttton_white_border"
        android:fontFamily="@string/medium_roboto"
        android:gravity="center"
        android:text="@string/btn_label_submit"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="15sp" />
</LinearLayout>

好吧,什么都不管用。注activity是fullScreen,也尝试过scrollview,不能更改设计。而EditText是片段。全屏片段也不起作用。隐藏视图在Lollypop中不起作用,但在kitkat中有效。

EN

回答 4

Stack Overflow用户

发布于 2017-05-18 07:26:15

不能与WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS一起使用adjustPan

试试这个:

代码语言:javascript
复制
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

或者这样:

代码语言:javascript
复制
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        w.getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
票数 1
EN

Stack Overflow用户

发布于 2016-03-11 17:32:33

试试这个:

android:windowSoftInputMode="adjustPan" >

票数 0
EN

Stack Overflow用户

发布于 2016-03-11 20:03:16

将此行添加到您的活动清单中。

代码语言:javascript
复制
<activity android:windowSoftInputMode="adjustResize"> </activity>

或添加

<activity android:windowSoftInputMode="adjustPan"> </activity>

正如Rohit Arya所建议的那样

备注:

在做了大量的搜索之后,我找到了这个。如果使用fullscreen标记(从活动中移除状态栏),则在不将活动包装在ScrollView中的情况下,不能使用"adjustResize“。

尝尝这个

示例

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent" >  
     ...

     ...

  </ScrollView>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35936489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档