This is my custom alert dialog code -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/inset_background_dialog"
android:padding="#dimen/dialog_elements_margin">
<TextView
android:id="#+id/text_add_address_title_addnewaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="#string/add_new_address_title_addnewaddress"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageView
android:id="#+id/image_close_dialogue_addnewaddress"
android:layout_width="#dimen/dialog_close_button"
android:layout_height="#dimen/dialog_close_button"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="4dp"
android:src="#drawable/ic_unchecked_black"/>
<EditText
android:id="#+id/edit_address_title_addnewaddress"
style="#style/roundedEditText"
android:layout_below="#+id/text_add_address_title_addnewaddress"
android:hint="#string/address_title_hint_addnewaddress"/>
<EditText
android:id="#+id/edit_mobile_number_addnewaddress"
style="#style/roundedEditText"
android:layout_below="#+id/edit_address_title_addnewaddress"
android:hint="#string/mobile_number_hint_addnewaddress"
android:inputType="number"/>
<EditText
android:id="#+id/edit_apartment_no_addnewaddress"
style="#style/roundedEditText"
android:layout_below="#+id/edit_mobile_number_addnewaddress"
android:hint="#string/house_no_hint_addnewaddress"/>
<EditText
android:id="#+id/edit_landmark_addnewaddress"
style="#style/roundedEditText"
android:layout_below="#+id/edit_apartment_no_addnewaddress"
android:hint="#string/landmark_hint_addnewaddress"/>
<EditText
android:id="#+id/edit_location_addnewaddress"
style="#style/roundedEditText"
android:layout_below="#+id/edit_landmark_addnewaddress"
android:hint="#string/address_hint_addnewaddress"/>
<Button
android:id="#+id/save_address_addnewaddress"
android:layout_width="match_parent"
android:layout_height="#dimen/dialog_elements_height"
android:layout_below="#+id/edit_location_addnewaddress"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/dialog_elements_margin"
android:background="#drawable/add_button_back_about_product"
android:text="#string/save_address_button_addnewaddress"
android:textAllCaps="false"
android:textColor="#color/tabSelectedTextColor"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The problem is, edit-text fields at the bottom are hidden behind the soft keyboard. I tried updating the android manifest to android:windowSoftInputMode="adjustResize" within the particular activity yet no luck. Any solution for this?
<ScrollView>
<LinearLayout android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<EditView />
<Button />
</LinearLayout>
set your UI inside the LinearLayout and try.
Related
I have a Button which is aligned at the bottom of my screen. This Button lifts up when the SoftKeyboard is opened. The page is blank in the middle. But it has some content at the top and some right above the bottom aligned Button. The problem is when the SoftKeyboard is opened, the blank area in the middle is filled with the content in the bottom. What I want instead is, the bottom content to stay where it was and be able to scroll behind to see it.
Use the below property for your activity in android manifest. So that screen component can be accessible even after after soft keyboard opened.
<activity
android:windowSoftInputMode="adjustResize" ... >
...
</activity>
Reference Link: https://developer.android.com/training/keyboard-input/visibility#Respond
For someone facing the same problem, I solved it this way
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<!--data binding declaration-->
</data>
<RelativeLayout
android:id="#+id/register_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary_amber_200"
tools:context=".login.view.EnterEmailActivity">
<LinearLayout
android:id="#+id/register_ll"
android:layout_width="match_parent"
android:layout_height="92dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:gravity="center">
<View
android:id="#+id/register_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/primary_amber_100"
android:layout_marginBottom="12dp"
android:visibility="invisible"/>
<Button
android:id="#+id/register_loginBtn"
style="#style/Button_Default_Dark_Grey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_small"
android:fitsSystemWindows="true"
android:text="#string/next"
android:layout_marginLeft="#dimen/margin_medium"
android:layout_marginRight="#dimen/margin_medium"/>
</LinearLayout>
<androidx.appcompat.widget.Toolbar
style="#style/ToolBar_Basic_Light"
android:background="#color/primary_amber_200"
android:elevation="0dp"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_medium">
<TextView
android:id="#+id/toolbar_title"
style="#style/Text_Basic_Toolbar" />
</androidx.appcompat.widget.Toolbar>
<ScrollView
android:id="#+id/register_sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none"
android:layout_below="#id/toolbar"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_medium"
android:layout_marginBottom="#dimen/margin_xlarge92">
<RelativeLayout
android:id="#+id/register_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/register_txtHeader"
style="#style/Text_Title_H1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_large"
android:text="#string/enter_email" />
<EditText
android:id="#+id/register_email"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_below="#id/register_txtHeader"
android:layout_marginTop="#dimen/margin_xlarge"
android:background="#color/primary_amber_100"
android:gravity="center_vertical"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:paddingLeft="#dimen/margin_medium"
android:paddingRight="#dimen/margin_small" />
<View
android:id="#+id/register_blank"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#id/register_email"
/>
<RelativeLayout
android:id="#+id/register_bottom_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_small"
android:layout_below="#id/register_blank"
android:layout_marginTop="#dimen/margin_xxxlarge"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/register_agreetxt"
style="#style/Text_Body_2"
android:textColor="#color/secondary_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="#string/agree" />
<TextView
android:id="#+id/register_terms"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_agreetxt"
android:text="#string/terms"
android:gravity="center"/>
<TextView
android:id="#+id/register_policy"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_agreetxt"
android:layout_marginLeft="#dimen/margin_xlarge"
android:layout_toRightOf="#id/register_terms"
android:text="#string/policy"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/register_have_accnt"
style="#style/Text_Body_2"
android:textColor="#color/secondary_grey_800"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_terms"
android:text="#string/already_have_an_account"
android:gravity="center"/>
<TextView
android:id="#+id/register_login"
style="#style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="#id/register_terms"
android:layout_marginLeft="#dimen/margin_xlarge"
android:layout_toRightOf="#id/register_have_accnt"
android:text="#string/login"
android:gravity="center"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</layout>
Dont forget to add android:windowSoftInputMode="stateVisible|adjustResize" to your activity in your manifest file.
I have a custom Dialog as shown below:
When I click on the Edit Text, The dialog is shifted upwards but half of the dialog becomes invisible as shown below:
I verified the issue on Android ICS and Gingerbread but it doesn't happen on Android Lollipop.
I appreciate your help for figuring out why.
Here is the custom dialog layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutChatInGame"
android:layout_width="305dp"
android:layout_height="190dp"
android:background="#drawable/dialog_table_border"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/roomlist_title_background">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_margin="5dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Game is on hold because the host paused the app"
android:id="#+id/lblOnHoldDialogMessage"
android:textColor="#color/progress_dialog_on_hold_text"
android:textSize="18dp"
android:singleLine="false"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/lblChatHistoryGameOnHold"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="bottom"
android:maxLines="5"
android:scrollbars="vertical"
android:textColor="#color/edit_text_general_text"
android:textColorHint="#color/edit_text_general_hint"
android:paddingRight="2dp"
android:paddingLeft="2dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/textChatGameOnHold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginStart="2dp"
android:layout_weight="1"
android:ems="10"
android:hint="#string/edit_text_send_chat_message"
android:imeOptions="flagNoExtractUi|actionDone"
android:inputType="text"
android:maxLength="100"
android:maxLines="1"
android:textColor="#color/edit_text_general_text"
android:textColorHint="#color/edit_text_general_hint"/>
<Button
android:id="#+id/btnSendGameOnHold"
style="#style/lightboxButton.Blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sendChatMessageInGame"
android:text="#string/btn_send"/>
</LinearLayout>
</LinearLayout>
Try to use also android:imeOptions="flagNoFullscreen" in your .xml. Recommend you to make some tests, using it with and without flagNoExtractUi. Please give me some feedback.
If all the other solutions are not working then try adding marginBottom in the top layout:
LinearLayout android:layout_marginBottom=20dp
You can get the desired behavior by making adjustResize flag for the windowSoftInputMode of the dialog in the manifest if your dialog is declared as an activity.
Like This:
android:windowSoftInputMode="adjustResize|stateHidden"
You can also directly try something like this directly on the dialog:
alertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I have an EdiText at the bottom of my layout.The issue I was having is that when it gets focus the screen shifts upwards to give space to soft keyboard.To resolve it I added
android:windowSoftInputMode="adjustResize"
inside my Activity declaration in manifest.Now the problem is that the edittext hides behind the softkeyboard although screen doesn't shifts.
If instead I put
android:windowSoftInputMode="adjustPan"
then the activity's main window shifts upward which i don't want.
How can i resolve this in such way that when EdiText gets focus activity's main window does NOT shift upwards to make room for the soft keyboard but the main window is resized including the EdiText so that keyboard comes below EdiText as seen in many apps.
Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_feed">
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical" />
<ListView
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F7F7"
android:paddingTop="10dp"
android:layout_above="#+id/border_view_comment"
android:divider="#android:color/transparent"
android:dividerHeight="10dp"
android:paddingBottom="10dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
<TextView
android:id="#+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/no_comment_msg"
android:visibility="gone"/>
<View
android:id="#+id/border_view_comment"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/commentlayout"
android:background="#C7C7C7"
android:visibility="gone"/>
<RelativeLayout
android:id="#+id/commentlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/comment_box_shadow"
android:padding="10dp">
<ImageView
android:id="#+id/commentor_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="15dp"
/>
<ImageView
android:id="#+id/clickPostComment"
android:layout_width="30dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:src="#drawable/post"
android:textColor="#color/white" />
<EditText
android:id="#+id/commentsPost"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignTop="#id/commentor_image"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/clickPostComment"
android:layout_toRightOf="#id/commentor_image"
android:background="#drawable/comment_edittext_bg"
android:hint="Comments"
android:singleLine="true"
android:maxLength="140"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/title_gray"
android:textColorHint="#d5d5d5"
android:textSize="15sp" />
<ImageView
android:layout_width="25dp"
android:layout_height="30dp"
android:layout_alignTop="#id/commentsPost"
android:layout_marginLeft="10dp"
android:layout_marginRight="-2dp"
android:layout_toLeftOf="#id/commentsPost"
android:scaleType="fitStart"
android:src="#drawable/comment_shape" />
</RelativeLayout>
</RelativeLayout>
make your view scrollable by embed your view inside Scrollview
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
.....
add your layout
......
</ScrollView>
If that doesn't help make you root layout as RelativeLayout and design your layout with RelativeLayout
I'm facing a View mixing up issue when I put Fragment which contains a EditText in a ViewPager.
You can see my actual layout design in image_1 .
Case 1: I put the Fragment inside a ViewPager and clicked on first EditText in the layout to enter something. But the result was image_2. All the View got mixed because there in no enough space for containing all View. But with respect to android's actual behavior all the Views inside the layout should move up and focus the current selected EditText.
Case 2: I put Fragment directly to Activity without ViewPager. I tried the same thing.(image_3). I got desired android behavior here.
1) Why is it so?2) How can I solve this issue?
image_1
image_2
image_3
My layout code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/container_dropshadow" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/content_margin"
android:background="#color/dark_background" >
<Button
android:id="#+id/sendButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:onClick="send"
android:text="#string/send" />
<EditText
android:id="#+id/descriptionEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/sendButton"
android:hint="#string/description"
android:inputType="textMultiLine|textNoSuggestions"
android:maxLength="500" />
<EditText
android:id="#+id/departmentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/descriptionEditText"
android:hint="Department"
android:inputType="textNoSuggestions"
android:singleLine="true" />
<EditText
android:id="#+id/subjectEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/departmentEditText"
android:hint="Subject"
android:inputType="textNoSuggestions"
android:singleLine="true" >
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/selectAFileLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/subjectEditText"
android:layout_margin="8dp"
android:background="#drawable/bg_browse"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/fileTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="6"
android:gravity="center"
android:padding="2dp"
android:text="Select a file"
android:textStyle="italic" />
<Button
android:id="#+id/browseFileButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="getFile"
android:text="..." />
</LinearLayout>
<TextView
android:id="#+id/messageTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/selectAFileLinearLayout"
android:layout_marginBottom="#dimen/upload_file_title_margin_bottom"
android:gravity="center_horizontal"
android:text="#string/upload_files_message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="#dimen/heading_font_size" />
</RelativeLayout>
</FrameLayout>
Add the following in manifest for your activity
android:windowSoftInputMode="adjustPan"
Yes, this is yet another edittext grow question on SO. And yes I've already gone through all those edittext grow questions. But this ones a bit specific.
UI:
A simple android layout with edittext and button below it. When text is less, the edittext view is still covering whole screen leaving space for button below.
Once user starts entering text, edittext grows vertically to accommodate text. At the same time, the button should also kept pushing downwards to let edittext grow.
User can vertically scroll through screen to view full text.
UI after entering significant text:
Here's the layout with edittext and button below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
android:clipToPadding="false"
android:fadingEdge="none"
android:fillViewport="true"
android:padding="13dp"
android:scrollbarStyle="outsideOverlay" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<!-- some fixed width image -->
<ImageView
android:id="#+id/someimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:src="#drawable/page_white_text" />
<EditText
android:id="#+id/some"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/someimage"
android:background="#null"
android:gravity="top"
android:minLines="10"
android:minHeight="50dp"
android:textColor="#222222"
android:textSize="15dp"
android:typeface="serif" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
This works more or less. But when I enter to much text, instead of pushing button downwards. It goes behind it like:
Any help here is much appreciated. Thanks :)
Here's my recommendation: inside the ScrollView, put a RelativeLayout in which you can place every element in a certain order using android:layout_below. For the auto-growing of your EditText, use this solution.
Let's see an example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<RelativeLayout
android:id="#+id/general2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20sp" >
<TextView
android:id="#+id/textFirstOpinion"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/titleFirstOpinion"
android:textStyle="bold"
android:textSize="23sp"
android:textColor="#FFFFFF"
android:layout_marginTop="10dp" />
<EditText
android:id="#+id/fieldFirstOpinion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textFirstOpinion"
android:minHeight="80sp"
android:isScrollContainer="true"
android:inputType="textMultiLine"
android:textSize="20sp"
android:gravity="top|left" />
<Button
android:id="#+id/button"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_below="#id/fieldFirstOpinion"
android:layout_centerHorizontal="true"
android:layout_marginTop="37sp"
android:textSize="23sp"
android:text="#string/textSendButton"
android:gravity="center_horizontal"
android:padding="10dp" />
</RelativeLayout>
</ScrollView>
try adding android:layout_below="#id/some" in your LinearLayout like
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical"
android:layout_below="#id/some" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Since you want the button to be at the bottom of the page, add the following line
android:layout_below="#+id/some"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
in your LinearLayout code here like
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/some"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:baselineAligned="true"
android:layout_marginTop="5dp"
android:padding="10dp"
android:orientation="vertical" >
Also make sure the layout:height parameter of EditText is set to wrap_content
Try this and tell me if it works or not