Android 移动键盘上方的浮动操作按钮
我有这个,当我打开(软件)键盘时,浮动操作按钮隐藏在键盘后面 有没有办法把它推到键盘上方 编辑: tab_random.xmlAndroid 移动键盘上方的浮动操作按钮,android,android-studio,android-softkeyboard,floating-action-button,Android,Android Studio,Android Softkeyboard,Floating Action Button,我有这个,当我打开(软件)键盘时,浮动操作按钮隐藏在键盘后面 有没有办法把它推到键盘上方 编辑: tab_random.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <View a
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="156dp"
android:background="@color/primary_color"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/from"
android:inputType="number"
android:imeOptions="actionNext"
android:layout_centerHorizontal="true"
android:hint="From"
android:paddingStart="5dp"
android:textColor="#FFF"
android:fontFamily="sans-serif-light"
android:textSize="44sp"
android:backgroundTint="@color/fab_ripple"
android:layout_marginStart="10dp"
/>
<EditText
android:textSize="44sp"
android:layout_marginStart="10dp"
android:paddingStart="5dp"
android:fontFamily="sans-serif-light"
android:layout_centerHorizontal="true"
android:layout_below="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To"
android:inputType="number"
android:imeOptions="actionSend"
/>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
fab:fab_colorNormal="@color/fab_normal"
fab:fab_colorPressed="@color/fab_pressed"
fab:fab_colorRipple="@color/fab_ripple"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="@dimen/fab_margin" />
</ScrollView>
活动\u main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="156dp"
android:background="@color/primary_color"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/from"
android:inputType="number"
android:imeOptions="actionNext"
android:layout_centerHorizontal="true"
android:hint="From"
android:paddingStart="5dp"
android:textColor="#FFF"
android:fontFamily="sans-serif-light"
android:textSize="44sp"
android:backgroundTint="@color/fab_ripple"
android:layout_marginStart="10dp"
/>
<EditText
android:textSize="44sp"
android:layout_marginStart="10dp"
android:paddingStart="5dp"
android:fontFamily="sans-serif-light"
android:layout_centerHorizontal="true"
android:layout_below="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To"
android:inputType="number"
android:imeOptions="actionSend"
/>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
fab:fab_colorNormal="@color/fab_normal"
fab:fab_colorPressed="@color/fab_pressed"
fab:fab_colorRipple="@color/fab_ripple"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="@dimen/fab_margin" />
</ScrollView>
解决方案是将整个布局放在滚动视图中 这样做
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="156dp"
android:background="@color/primary_color"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/from"
android:inputType="number"
android:imeOptions="actionNext"
android:layout_centerHorizontal="true"
android:hint="From"
android:paddingStart="5dp"
android:textColor="#FFF"
android:fontFamily="sans-serif-light"
android:textSize="44sp"
android:backgroundTint="@color/fab_ripple"
android:layout_marginStart="10dp"
/>
<EditText
android:textSize="44sp"
android:layout_marginStart="10dp"
android:paddingStart="5dp"
android:fontFamily="sans-serif-light"
android:layout_centerHorizontal="true"
android:layout_below="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To"
android:inputType="number"
android:imeOptions="actionSend"
/>
</ScrollView>
</RelativeLayout>
由于您的项目现在位于scrollview中,它们将滚动。您的布局现在如下所示:
<Relative Layout>
<View/>
<EditText/>
<other stuff.../>
</RelativeLayout>
您需要在RelativeLayout标记中添加一个scrollview。另外,scrollview不喜欢有多个直接子视图,所以您需要在scrollview内部有一个Relativelayout。因此,您的布局最终将如下所示:
<RelativeLayout> (this was already here)
<ScrollView> (this is new)
<RelativeLayout> (this is also new)
<View, EditText, Etc. in here/> (this is what used to be inside that original relative layout.)
</RelativeLayout> (closing up the new Relativelayout)
</ScrollView> (closing the new Scrollview)
</RelativeLayout> (closing the original Relative Layout.)
(这里已经有了)
(这是新的)
(这也是新的)
(这是原始相对布局中的内容。)
(关闭新的Relativelayout)
(关闭新的滚动视图)
(关闭原始相对布局。)
TRU执行此操作。这对我有用
将stateVisible | adjustPan添加到清单文件中的活动中
<activity
android:name="com.comapny.applicationname.activityname"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
试试这个:
活动\u main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="156dp"
android:background="@color/primary_color"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/from"
android:inputType="number"
android:imeOptions="actionNext"
android:layout_centerHorizontal="true"
android:hint="From"
android:paddingStart="5dp"
android:textColor="#FFF"
android:fontFamily="sans-serif-light"
android:textSize="44sp"
android:backgroundTint="@color/fab_ripple"
android:layout_marginStart="10dp"
/>
<EditText
android:textSize="44sp"
android:layout_marginStart="10dp"
android:paddingStart="5dp"
android:fontFamily="sans-serif-light"
android:layout_centerHorizontal="true"
android:layout_below="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="To"
android:inputType="number"
android:imeOptions="actionSend"
/>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
fab:fab_colorNormal="@color/fab_normal"
fab:fab_colorPressed="@color/fab_pressed"
fab:fab_colorRipple="@color/fab_ripple"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar" />
<slidingModel.SlidingTabLayout
android:layout_below="@+id/toolbar"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="@color/primary_color"
/>
<android.support.v4.view.ViewPager
android:layout_below="@id/tabs"
android:id="@+id/pager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="@dimen/fab_margin" />
</ScrollView>
我所做的就是把晶圆厂放在一个
滚动视图中我有一个类似的问题,@MrPlow建议,但他在原来的RelativeLayout中添加了一个滚动视图,然后在ScrollView中添加了另一个RelativeLayout(以保留格式结构),我只是将整个布局包装在一个ScrollView中,它“刚刚工作”。OP的最终结果将是:
<Scrollview>
<RelativeLayout>
<View/>
<EditText/>
<other stuff.../>
</RelativeLayout>
</Scrollview>
FAB是否移动到键盘上方,具体取决于清单文件和标记“android:WindowsofInputMode”
要使其移动到软键盘上方,我使用以下代码(清单文件):
要使其位于软键盘后面,请使用以下命令:
<activity
android:name=".activities.YourActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
我该怎么做?我会发布我的布局,你可以告诉我怎么做。当我输入代码时,FAB仍在键盘后面。发布我的活动\u main.xmlFAB仍在键盘后面:(发布我的活动主题,如果它有帮助的话。你需要做的就是将此修复应用于你的活动主题布局,而不是其他任何东西。将滚动视图放在整个页面上,除了最外层的视图组。我想这是你的布局问题。我将发布我的活动主题。你添加了@Raj answer吗?试试他的way@IntelliJAmiya是 啊是的。它所做的只是在我打开应用程序时打开键盘。对我一点帮助都没有:(你想把它显示在键盘的顶部,还是稍微向上移动,这样它就可以显示?。如果你把它放在键盘的顶部,键盘就不能按。我想把它显示在键盘的顶部,这样它就可以显示出来。如果你想把fab按钮放在键盘后面,就这样做吧,谢谢