【问题标题】:Soft keyboard pushing up layout or hidding action bar软键盘上推布局或隐藏操作栏
【发布时间】:2014-12-02 11:41:46
【问题描述】:

我的项目中有软键盘问题。我已经用

设置了我的清单文件
android:windowSoftInputMode="adjustPan"

这样我的键盘和 EditText 就可见了。但就像下面链接的问题一样,屏幕底部的按钮随着键盘向上推。

https://stackoverflow.com/questions/5516216/how-to-avoid-soft-keyboard-pushing-up-my-layout#=

我的布局由一个具有 2 个线性布局(一个顶部,一个带按钮的底部)的 RelativeLayout 基础和一个位于中间的 ScrollView 组成,用于获取其余内容。当我尝试设置选项时

android:isScrollContainer="false" 

这次在我的 ScrollView 上,我的操作栏向上推并从布局中隐藏。

我想要一种方法让键盘克服底部线性布局滚动滚动视图的内容并且不向上推操作栏。

有什么建议吗?

谢谢!

顺便说一下,我的滚动视图有很多微调器、EditTexts 和一个 AutoSuggest

工作“解决方案” --> 帮助找到答案

如果我将 RelativeLayout 更改为具有垂直方向的 LinearLayout 并从清单中删除此属性 android:windowSoftInputMode="adjustPan" 我有我想要的效果,操作栏不会消失并且底部按钮不会向上推。问题是,我被底部按钮弄丢了,要堆叠在底部。有时 ScrollView 比设备窗口小,所以这个解决方案对我有帮助,但现在解决了我真正的问题。

信息:

<activity
   android:name=".app.HomeActivity"
   android:label="@string/title_activity_home"
   android:launchMode="singleTop"
   android:screenOrientation="portrait"
   android:windowSoftInputMode="adjustPan"/>

申请主题:

<style name="CustomActionBarTheme" parent="@style/AppTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/shape_bar</item>
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/fragment_detalhes_pedido2_linear_top"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:background="@color/font_white_color"
            android:orientation="horizontal"
            android:gravity="center_vertical">

            <ImageView
                android:layout_width="@dimen/icon_size_default"
                android:layout_height="@dimen/icon_size_default"
                android:layout_gravity="center_vertical"
                android:contentDescription="@string/app_name"
                android:src="@drawable/icon_lista_clientes" />

            <br.newm.afvcore.layout.NewmTextView
                android:id="@+id/fragment_detalhes_pedido2_txt_cliente"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:text="Cliente Selecionado"
                android:textColor="@color/font_default_color"
                android:textSize="@dimen/font_size_default"
                android:textStyle="bold|italic" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#696969" />

    </LinearLayout>

    <ScrollView
        android:id="@+id/fragment_scroll_datalhes2_miolo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/fragment_detalhes_pedido2_linear_bottom"
        android:layout_below="@+id/fragment_detalhes_pedido2_linear_top"></ScrollView>

    <LinearLayout
        android:id="@+id/fragment_detalhes_pedido2_linear_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="@dimen/activity_vertical_margin"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="@color/cinza_linha" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:orientation="horizontal"
            android:weightSum="1">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="0.35">

                <br.newm.afvcore.layout.NewmTextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/azul_letras"
                    android:textSize="@dimen/font_size_default"
                    android:text="Qtd:"
                    android:textStyle="bold" />

                <br.newm.afvcore.layout.NewmTextView
                    android:id="@+id/fragment_detalhes_pedido2_txt_qtd"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/font_default_color"
                    android:textSize="@dimen/font_size_default"
                    android:text="999999999"
                    android:layout_marginLeft="5dp"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="0.65"
                android:layout_marginLeft="5dp"
                android:gravity="right">

                <br.newm.afvcore.layout.NewmTextView
                    android:id="@+id/fragment_detalhes_pedido2_lbl_valor_total"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/azul_letras"
                    android:textSize="@dimen/font_size_default"
                    android:text="Total:"
                    android:textStyle="bold" />

                <br.newm.afvcore.layout.NewmTextView
                    android:id="@+id/fragment_detalhes_pedido2_txt_valor_total"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/font_default_color"
                    android:textSize="@dimen/font_size_default"
                    android:text="R$ 9.999.999,00"
                    android:layout_marginLeft="5dp"
                    android:textStyle="bold" />

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/fragment_detalhes_pedido2_linear_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:gravity="center_vertical">

            <Button
                android:id="@+id/fragment_detalhes_pedido2_btn_salvar"
                android:layout_width="0dip"
                android:layout_height="@dimen/btn_size_default"
                android:layout_weight="1"
                android:text="Salvar"
                android:background="@drawable/shape_btn_azul"
                android:textColor="@color/font_white_color"
                android:textSize="@dimen/font_size_default"
                android:textStyle="bold|italic" />

            <Button
                android:id="@+id/fragment_detalhes_pedido2_btn_reenviar_copia"
                android:layout_width="0dip"
                android:layout_height="@dimen/btn_size_default"
                android:layout_weight="1"
                android:text="Reenviar cópia do pedido"
                android:background="@drawable/shape_btn_azul"
                android:textColor="@color/font_white_color"
                android:textSize="@dimen/font_size_default"
                android:textStyle="bold|italic"
                android:visibility="gone" />

            <Button
                android:id="@+id/fragment_detalhes_pedido2_btn_finalizar"
                android:layout_width="0dip"
                android:layout_height="@dimen/btn_size_default"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_weight="1"
                android:text="Finalizar"
                android:background="@drawable/shape_btn_azul"
                android:textColor="@color/font_white_color"
                android:textSize="@dimen/font_size_default"
                android:textStyle="bold|italic" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

【问题讨论】:

标签: android android-layout android-softkeyboard


【解决方案1】:

回答这个问题可能已经晚了,但我遇到了它并找到了解决方案,所以想分享它。

给属性

android:isScrollContainer="false" 给你的父母Layout

android:windowSoftInputMode="adjustResize" for Activity in AndroidManifest.xml

【讨论】:

  • 我有一个相当复杂的布局,它有一个约束布局,其中项目约束在嵌套滚动视图的底部,除非我添加了愚蠢的边距底部但只是添加了 android:isScrollContainer ="true" 修复了非常感谢
【解决方案2】:

android:windowSoftInputMode="adjustNothing"试试这个

【讨论】:

    【解决方案3】:

    在你的清单中试试这个:android:windowSoftInputMode="adjustResize|stateHidden"

    【讨论】:

    • 试试这个 android:windowSoftInputMode="stateHidden|stateUnchanged|adjustPan"。让我知道
    • 这一次,actionbar 被隐藏但没有向上推按钮。与设置 android:windowSoftInputMode="adjustPan" 的效果相同
    • 当然是问题描述,顺便说一下我也使用片段。 (不知道有没有关系)
    • 将 android:windowSoftInputMode="adjustPan" 更改为 android:windowSoftInputMode="stateHidden|stateUnchanged|adjustPan"。你有没有写任何代码来删除操作栏
    • 已经尝试过 =/ 操作栏从布局中隐藏,但键盘覆盖了底部按钮。而且我没有编写代码来删除操作栏
    猜你喜欢
    • 2016-02-01
    • 2012-01-03
    • 1970-01-01
    • 2021-08-27
    • 2016-03-10
    • 2018-08-28
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    相关资源
    最近更新 更多