当输入键盘可见时,按钮页脚不起作用
Button footer is not working when the input keyboard is visible
我有一个 activity,在 activity 的顶部有几个 editText
,在页脚有两个 buttons
。
当我按下其中一个编辑文本时,会出现键盘和页脚 adjustResize
。这是我想要的行为。
我的问题是,当我尝试按其中之一时 buttons
(当键盘可见时)键盘被隐藏并且按下按钮的动作不起作用。
我的问题是,当键盘在 activity.
中可见时,如何让页脚正常工作
清单中我的activity:
<activity
android:name=".activity.InitSessionActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
我根据这个答案的解决方案创建了我的activity:
How to adjust layout when soft keyboard appears
我的activityxml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/screen"
android:fillViewport="true"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/screen"
android:id="@+id/ly_general"
android:fitsSystemWindows="true">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
android:layout_marginTop="172dp"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:layout_centerHorizontal="true"
android:id="@+id/textInputLayout">
</android.support.design.widget.TextInputLayout>
<include layout="@layout/footer" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:id="@+id/textInputLayoutEmail"
android:layout_below="@+id/text_init_session"
android:layout_marginTop="@dimen/padding_10">
<EditText
android:id="@+id/login_ed_email"
android:layout_width="314dp"
android:layout_height="wrap_content"
android:hint="@string/login_hint_email"
android:drawablePadding="5dp"
android:inputType="textEmailAddress"
android:textColorHint="@color/white3"
style="@style/edittextWithTextInputLayout"
android:transitionName="@string/email"
android:nextFocusDown="@+id/login_ed_password"
android:layout_marginTop="9dp"
android:layout_below="@+id/text_init_session"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:backgroundTint="@color/secundary_foreground" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:id="@+id/textInputLayout2"
android:layout_marginTop="16dp"
android:layout_below="@+id/textInputLayoutEmail">
<EditText
android:id="@+id/login_ed_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contraseña"
android:textColorHint="@color/colorPrimary"
style="@style/edittextWithTextInputLayout"
android:transitionName="@string/password"
android:drawableLeft="@drawable/login_ico_password"
android:drawablePadding="5dp"
android:nextFocusDown="@+id/login_btn_enter"
android:nextFocusUp="@+id/login_ed_email"
android:inputType="textPassword"
android:backgroundTint="@color/secundary_foreground" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/login_tx_forgot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textColor="@color/secundary_foreground"
android:padding="@dimen/margin_13"
android:text="@string/login_forgot_password"
android:layout_below="@+id/textInputLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="@dimen/padding_16"/>
<TextView
android:text="@string/login_title_init_session"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:padding="10dp"
android:textSize="@dimen/text_size_22"
android:id="@+id/text_init_session"
android:layout_marginTop="17dp"
android:layout_marginLeft="@dimen/padding_13"
android:layout_below="@+id/image"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="@+id/image"
android:layout_width="134dp"
android:layout_height="45dp"
android:src="@drawable/logo_loycus_new"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/textInputLayoutEmail"
android:layout_alignStart="@+id/textInputLayoutEmail" />
</RelativeLayout>
</ScrollView>
福特尔:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="@color/colorPrimary">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/backgroundScreens"
android:id="@+id/view"/>
<Button
android:text="@string/volver"
android:textAllCaps="false"
android:layout_width="@dimen/button_folder_widht"
android:layout_height="@dimen/button_folder_height"
android:id="@+id/buttonComeBack"
android:background="@drawable/btn_selecto_come_back"
android:textColor="@color/white"
android:layout_marginLeft="@dimen/margin_16"
android:layout_marginTop="@dimen/padding_10"/>
<Button
android:layout_marginTop="@dimen/padding_10"
android:text="@string/enter"
android:textAllCaps="false"
android:layout_width="@dimen/button_folder_widht"
android:layout_height="@dimen/button_folder_height"
android:background="@drawable/btn_selector_green"
android:textColor="@color/colorPrimary"
android:id="@+id/login_loycus"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="@dimen/margin_16"/>
</RelativeLayout>
将页脚编辑为:-
<include layout="@layout/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
从 ScrollView 中删除它
android:layout_alignParentBottom="true"
从 ID 为 ly_general
的相对布局中删除它
android:fitsSystemWindows="true"
将此添加到滚动视图
android:fitsSystemWindows="true"
编辑:-
如果您不想将页脚与底部对齐,请删除此行
android:layout_alignParentBottom="true"
并调整它放在 UI 上的任何位置。
我刚用我写的页脚试用了你的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="@android:color/black">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 2"/>
</LinearLayout>
一切似乎都运行良好。
你能再解释一下这个问题吗?或者 post 你的 code/footer?
我有一个 activity,在 activity 的顶部有几个 editText
,在页脚有两个 buttons
。
当我按下其中一个编辑文本时,会出现键盘和页脚 adjustResize
。这是我想要的行为。
我的问题是,当我尝试按其中之一时 buttons
(当键盘可见时)键盘被隐藏并且按下按钮的动作不起作用。
我的问题是,当键盘在 activity.
中可见时,如何让页脚正常工作清单中我的activity:
<activity
android:name=".activity.InitSessionActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
我根据这个答案的解决方案创建了我的activity: How to adjust layout when soft keyboard appears
我的activityxml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/screen"
android:fillViewport="true"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/screen"
android:id="@+id/ly_general"
android:fitsSystemWindows="true">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
android:layout_marginTop="172dp"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:layout_centerHorizontal="true"
android:id="@+id/textInputLayout">
</android.support.design.widget.TextInputLayout>
<include layout="@layout/footer" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:id="@+id/textInputLayoutEmail"
android:layout_below="@+id/text_init_session"
android:layout_marginTop="@dimen/padding_10">
<EditText
android:id="@+id/login_ed_email"
android:layout_width="314dp"
android:layout_height="wrap_content"
android:hint="@string/login_hint_email"
android:drawablePadding="5dp"
android:inputType="textEmailAddress"
android:textColorHint="@color/white3"
style="@style/edittextWithTextInputLayout"
android:transitionName="@string/email"
android:nextFocusDown="@+id/login_ed_password"
android:layout_marginTop="9dp"
android:layout_below="@+id/text_init_session"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:backgroundTint="@color/secundary_foreground" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/inputTextLayout"
app:hintTextAppearance="@style/edittextWithTextInputLayout"
android:id="@+id/textInputLayout2"
android:layout_marginTop="16dp"
android:layout_below="@+id/textInputLayoutEmail">
<EditText
android:id="@+id/login_ed_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contraseña"
android:textColorHint="@color/colorPrimary"
style="@style/edittextWithTextInputLayout"
android:transitionName="@string/password"
android:drawableLeft="@drawable/login_ico_password"
android:drawablePadding="5dp"
android:nextFocusDown="@+id/login_btn_enter"
android:nextFocusUp="@+id/login_ed_email"
android:inputType="textPassword"
android:backgroundTint="@color/secundary_foreground" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/login_tx_forgot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textColor="@color/secundary_foreground"
android:padding="@dimen/margin_13"
android:text="@string/login_forgot_password"
android:layout_below="@+id/textInputLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="@dimen/padding_16"/>
<TextView
android:text="@string/login_title_init_session"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:padding="10dp"
android:textSize="@dimen/text_size_22"
android:id="@+id/text_init_session"
android:layout_marginTop="17dp"
android:layout_marginLeft="@dimen/padding_13"
android:layout_below="@+id/image"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="@+id/image"
android:layout_width="134dp"
android:layout_height="45dp"
android:src="@drawable/logo_loycus_new"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/textInputLayoutEmail"
android:layout_alignStart="@+id/textInputLayoutEmail" />
</RelativeLayout>
</ScrollView>
福特尔:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="@color/colorPrimary">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/backgroundScreens"
android:id="@+id/view"/>
<Button
android:text="@string/volver"
android:textAllCaps="false"
android:layout_width="@dimen/button_folder_widht"
android:layout_height="@dimen/button_folder_height"
android:id="@+id/buttonComeBack"
android:background="@drawable/btn_selecto_come_back"
android:textColor="@color/white"
android:layout_marginLeft="@dimen/margin_16"
android:layout_marginTop="@dimen/padding_10"/>
<Button
android:layout_marginTop="@dimen/padding_10"
android:text="@string/enter"
android:textAllCaps="false"
android:layout_width="@dimen/button_folder_widht"
android:layout_height="@dimen/button_folder_height"
android:background="@drawable/btn_selector_green"
android:textColor="@color/colorPrimary"
android:id="@+id/login_loycus"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="@dimen/margin_16"/>
</RelativeLayout>
将页脚编辑为:-
<include layout="@layout/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
从 ScrollView 中删除它
android:layout_alignParentBottom="true"
从 ID 为 ly_general
的相对布局中删除它android:fitsSystemWindows="true"
将此添加到滚动视图
android:fitsSystemWindows="true"
编辑:-
如果您不想将页脚与底部对齐,请删除此行
android:layout_alignParentBottom="true"
并调整它放在 UI 上的任何位置。
我刚用我写的页脚试用了你的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="@android:color/black">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 2"/>
</LinearLayout>
一切似乎都运行良好。 你能再解释一下这个问题吗?或者 post 你的 code/footer?