Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用键盘时如何隐藏底部导航视图?_C#_Android_Android Layout_Xamarin.android_Android Bottom Nav View - Fatal编程技术网

C# 使用键盘时如何隐藏底部导航视图?

C# 使用键盘时如何隐藏底部导航视图?,c#,android,android-layout,xamarin.android,android-bottom-nav-view,C#,Android,Android Layout,Xamarin.android,Android Bottom Nav View,对于我在主要任务中的应用程序,我从用户那里获得了相当多的输入。当前,当他们进入输入时,键盘升起,底部导航视图在其上方保持可见。然而,我想发生的是,当键盘弹出时,底部导航应该消失,用户看不到。所以我要这样做吗 包含底部导航栏的MainActivity的代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

对于我在主要任务中的应用程序,我从用户那里获得了相当多的输入。当前,当他们进入输入时,键盘升起,底部导航视图在其上方保持可见。然而,我想发生的是,当键盘弹出时,底部导航应该消失,用户看不到。所以我要这样做吗

包含底部导航栏的MainActivity的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/maintoolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@id/maintoolbar"
        android:layout_above="@+id/bottom_navigation"/>

    <android.support.design.widget.BottomNavigationView     
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:elevation="4dp"
        app:menu="@menu/bottom_navigation_main"/>

</RelativeLayout>


我希望转换过程尽可能快、干净,这样用户几乎不会注意到更改。

在AndroidManifest.xml文件中MainActivity的活动标记中添加以下内容:

android:windowSoftInputMode="adjustPan"
编辑:如果上述解决方案不起作用,解决方法: 在每个edittext上添加焦点更改侦听器。如果它接收到焦点,则键盘将显示。所以隐藏你的底视图

View.OnFocusChangeListener myFocusListener = new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (hasFocus) {
            bottomNavigationView.setVisiblity(View.GONE);
        } else {

            bottomNavigationView.setVisiblity(View.VISIBLE);

        }
    }
};

editText1.setOnFocusChangeListener(myFocusListener);
editText2.setOnFocusChangeListener(myFocusListener);
...

您可以尝试在活动顶部添加
WindowSoftInputMode=SoftInput.AdjustPan
,如下所示:

[Activity(WindowSoftInputMode=SoftInput.AdjustPan)]

另一个选项是向键盘添加ViewSourceObserver,并在键盘出现时隐藏BottomNavigationView,然后在键盘消失时显示BottomNavigationView。不过,第一个选项可能更好。

你知道这是一个c版本吗?请补充,这是无效的,因为我有很多不同片段的编辑文本