当软键盘处于活动状态并且我已成功实现它时,我已经研究了很多调整布局但是当我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"在清单文件中的活动标签中使用它时问题就出现了.
为此,我使用android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"了不同的选项,但没有运气.
之后,我以FullScreen编程方式实现并尝试了各种布局,FullScreen但都是徒劳的.
我引用了这些链接,并在此处查看了许多与此问题相关的帖子:
http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
http://davidwparker.com/2011/08/30/android-how-to-float-a-row-above-keyboard/
这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/masterContainerView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<ScrollView android:id="@+id/parentScrollView"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/setup_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Setup - Step 1 of 3"
android:textColor="@color/top_header_txt_color" android:textSize="20dp"
android:padding="8dp" android:gravity="center_horizontal" />
<TextView android:id="@+id/txt_header" android:layout_width="fill_parent"
android:layout_height="40dp" android:text="AutoReply:"
android:textColor="@color/top_header_txt_color" android:textSize="14dp"
android:textStyle="bold" android:padding="10dp"
android:layout_below="@+id/setup_txt" />
<EditText android:id="@+id/edit_message"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Some text here." android:textSize="16dp"
android:textColor="@color/setting_editmsg_color" android:padding="10dp"
android:minLines="5" android:maxLines="6" android:layout_below="@+id/txt_header"
android:gravity="top" android:scrollbars="vertical"
android:maxLength="132" />
<ImageView android:id="@+id/image_bottom"
android:layout_width="fill_parent" android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我有一个使用这种布局的虚假对话框:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/containerPageConatiner">
<FrameLayout android:id="@+id/dialogHolder"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="15dp"
android:layout_gravity="center"
android:background="@drawable/panel_picture_frame_bg_focus_blue"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我<FrameLayout>根据打开的对话框放置一个片段- 控制Dialog的活动如下所示:
<activity
android:label="@string/app_name"
android:name=".activity.DialogActivity"
android:theme="@style/CustomTheme.Screen.Transparent"
android:windowSoftInputMode="adjustResize">
Run Code Online (Sandbox Code Playgroud)
不幸的是,当您单击对话框内的编辑文本时,不会进行大小调整.在windowSoftInputMode字面上没有什么区别的功能是一样的全景模式.
文档说"这当然只适用于具有可调整区域的应用程序,可以缩小以留出足够的空间",但不会告诉您"可调整区域"的含义,并让我认为在某种程度上我不喜欢Ť有一个可调整大小的面积?
如果有人知道什么事可以帮助我吗?
编辑
如此围绕对话框不会改变任何东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containerPageConatiner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/dialogHolder"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="15dp"
android:layout_gravity="center"
android:background="@drawable/panel_picture_frame_bg_focus_blue"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
EDIT2
Scrollview作为父级也无济于事:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containerPageConatiner"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/dialogHolder"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我的活动的布局如下所示.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout android:id="@+id/title_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:background="@drawable/bg_title" />
<LinearLayout android:id="@+id/main"
android:width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip" >
<EditText android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some search terms"
android:singleLine="true"
android:layout_weight="1" />
<Button android:id="@+id/btn_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_hide"
android:layout_marginLeft="6dip" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
因此,搜索框固定在屏幕的底部.
但是,当用户单击EditText时,软键盘会显示并将布局推出屏幕,但搜索框除外.
我刚刚开始使用Android,所以我在这里做错了什么?
有问题谈论这个问题,但我没有通过现有的答案解决我的问题.
这是我的styles-v21.xml:
<style name="MainTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:colorBackground">#EEEEEE</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我当然为相关的Activity设置了windowSoftInputMethod ="adjustResize".
这是我的layout.xml,注意根FrameLayout用于特定功能,因此需要它:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/rl_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--This View is used to fill the space of status bar-->
<View
android:id="@+id/statusbar"
android:layout_width="match_parent"
android:layout_height="@dimen/statusbar_size"/>
<!--I've set this toolbar as Actionbar-->
<android.support.v7.widget.Toolbar
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="@id/statusbar"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/actionbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Two EditTexts inside -->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
当我没有触摸EditText时,一切看起来都很好:状态栏View保持原样,导航栏不覆盖内容(不要让内容不可见,但实际上内容不在其中).
在类似的问题中,人们经常教我们设置fitsSystemWindow ="true",我在layout.xml中的不同布局中做了这个,得到了不同的结果.
设置fitsSystemWindow ="true":
1.FrameLayout:AdjustResize有效,但状态栏View现在保持在真实状态栏下方.状态栏的颜色变为windowBackground.导航栏变得完全透明,因为它显示了添加此片段的其他片段内容.
2.First RelativeLayout:AdjustResize有效,但状态栏View低于实际状态栏.导航栏不太透明,无法显示其他片段,但覆盖内容.
ScrollView中的3&4.ScrollView和RelativeLayout:AdjustResize不起作用,其他条件与条件2相同.
我还使用了一种方法来编写我自己的FrameLayout,如下所示:https://stackoverflow.com/a/22266717/3952691 但正如作者所说,设置底部会导致错误.因为我使用半透明导航栏,我还需要绘制底部插图.我尝试升级版本:https …
当键盘显示时,我无法向上推整个回收器视图,它切断了之前的消息。我正在创建一个看起来像这个 xml 的聊天视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/commentsParentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/noCommentsResults"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lineSep"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/noCommentsFound"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pullToLoadMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lineSep"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:paddingBottom="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/comments_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<View
android:id="@+id/lineSep"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/commentsAddLayout"
android:background="@color/horizontalLine" />
<LinearLayout
android:id="@+id/commentsAddLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/emojiSelector"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1"
android:src="@drawable/emoji" />
<EditText
android:id="@+id/commentText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="4"
android:background="@android:color/transparent"
android:hint="@string/add_comment"
android:maxLength="150" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/horizontalLine" />
<TextView …Run Code Online (Sandbox Code Playgroud) 我在android棒棒糖上遇到问题,当软键盘出现时,屏幕不会调整大小.
这是我所做的一项活动的明显介绍示例:
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
Run Code Online (Sandbox Code Playgroud)
是否有新的东西被添加,我们必须考虑到Android 5.0?scrollview在android <5.0上运行正常.
android android-manifest android-layout android-softkeyboard android-scrollview