Disabled EditText element display keyboard - android

I need to figure out why I keep getting the android keyboard displayed, since I have my EditText with the enabled attribute set to false. The root element of my layout file is a ScrollView. When I take out the ScrollView element, it works perfectly with a root element like LinearLayout.
Is this the expected behavior for a ScrollView, or it's just a buggy thing? (I do not get the point to have a ScrollView with a text editable element behavior, if that is the case).
Just as an extra, some of my layout code...
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet"
android:layout_marginBottom="20dp"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/input_name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_idcard_icon"
/>
<EditText
android:id="#+id/personal_setting_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/input_name_icon"
android:enabled="false"
android:text="First Name" />
Don't stress out, I'll change my string and dimensions properly... ;D

If you want to avoid the android keyboard from showing up every time you open your activity with ScrollView you have to place android:focusableInTouchMode="true" but not in the EditText. You have to put it in the ScrollView like this:
<ScrollView 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"
tools:context="copsonic.com.SoundExchange.demoApp.FragmentTransmitter">
<!-- Common template for all fragments -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusableInTouchMode="true">
<EditText
android:id="#+id/editTextmessage2Send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/button_send_msg"
android:ems="10"
android:hint="#string/edit_message" >
</EditText>
</RelativeLayout>
</ScrollView>

Related

AlignParentBottom button overlaps Textview on Scroll/Focus

Currently, I have a few Android xml layouts with multiple Textviews that data can be entered into. At the bottom of the relative layout is a button with the attribute android:layout_alignParentBottom="true" with the text "Save Changes", which is expected to display above the keyboard, when the keyboard pops up.
However, when clicking on a textview towards the bottom of the list, once focused, the "Save Changes" button is overlapping with the focused Textview.
Note: it IS possible to manually scroll down a bit more yourself, to then see the Textview.
Ideally the functionality here would be to adjust the scrollTo() to effectively scroll to the focused element and place it into view just above the "Save Changes" button.
I've tried setting this value in the activitys attributes in the manifest:
android:windowSoftInputMode="adjustResize"
Along with wrapping the Relative Layout in a LinearLayout, or adding padding to the bottom of the ScrollView to no avail.
Here's my current XML excluding the Title bar:
<ScrollView
android:id="#+id/edit_info_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:layout_below="#id/activity_title_border_bottom">
<LinearLayout
android:id="#+id/edit_info_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/huge_padding"
android:layout_marginBottom="#dimen/huge_padding">
<TextView
android:id="#+id/account_firstname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/label_firstname"
style="#style/label_text"/>
<EditText
android:id="#+id/account_firstname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="#style/EditTextStyle" />
<TextView
android:id="#+id/account_lastname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/label_lastname"
style="#style/label_text"/>
<EditText
android:id="#+id/account_lastname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="#style/EditTextStyle" />
<TextView
android:id="#+id/account_phone_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/label_phone"
style="#style/label_text"/>
<EditText
android:id="#+id/account_phone_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:maxLines="1"
style="#style/EditTextStyle" />
<TextView
android:id="#+id/account_email_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/label_email"
style="#style/label_text"/>
<EditText
android:id="#+id/account_email_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:maxLines="1"
android:layout_marginBottom="#dimen/activity_vertical_margin"
style="#style/EditTextStyle" />
<TextView
android:id="#+id/account_password_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/label_password"
style="#style/label_text"/>
<EditText
android:id="#+id/account_password_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1"
android:layout_marginBottom="#dimen/activity_vertical_margin"
style="#style/EditTextStyle" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/save_changes"
android:background="#drawable/button_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="#string/save_changes"
android:textColor="#color/White"
android:textStyle="bold"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
style="style/Widget.AppCompat.Button.Colored"/>
</RelativeLayout>
What would be the best way to scroll to the focused textview, while still showing the "Save changes" button above the keyboard?
Any ideas are greatly appreciated!
It looks like your layout is approximately:
<RelativeLayout>
<ScrollView>
...
</ScrollView>
<Button/>
</RelativeLayout>
The problem with this structure is that the ScrollView fills the whole screen. In other words, a portion of the ScrollView is always "behind" the Button... it's just only problematic when the keyboard comes up.
Instead, I think you should use this layout:
<LinearLayout
android:orientation="vertical"
...>
<ScrollView
android:layout_height="0dp"
android:layout_weight="1"
...>
...
</ScrollView>
<Button/>
</LinearLayout>
By doing this, you make sure that it's impossible to have content in your ScrollView go behind your button, but you still get the Button pushed all the way to the bottom of the screen.

Containers are getting stuck behind the app header (Android)

I've been trying to create an app that would allow a user to enter timetable information but i'm getting stuck at the design part, the first "Edit Text" container is getting stuck behind the title header of the app and i'm not sure why. I'd like to make it so it's forced below the header (and the other containers are force below the one above it, like a stack)
Image showing problem
There is another container above the "Day of Week", you can just see the bottom part of it sticking out below the header. Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<EditText
android:id="#+id/ModuleCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/module_code"
android:inputType="text"
android:gravity="fill"
android:layout_gravity="bottom"
android:layout_weight="0.14"
/>
<EditText
android:id="#+id/DayOfWeek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/day_of_week"
android:inputType="text" />
<EditText
android:id="#+id/StartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/start_time"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/Duration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/duration"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/SessionType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/type_of_session"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/Room"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/room"
android:visibility="gone"
android:inputType="text" />
<ListView
android:id="#+id/myListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.07" />
</LinearLayout>
I had the exact same problem, i just added a margin-top to the LinearLayout so it clears the header. for example:
note here i use a percentRelativeLayout, but this works with all layouts.
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:layout_marginTop="55dp"<--- this one!
android:padding="10dp">
it is because the action bar is added externally on top of the view
you could either remove the action bar and add it to your xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="#298859"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
or simply as add a margin top to your first item
<EditText
android:id="#+id/ModuleCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/module_code"
android:inputType="text"
android:layout_marginTop="30dp"/>

Android TextAlignment in EditText stops keyboard lifting up

I have strange problem. When I set Text Alignment of my EditText to center the keyboard is not lifting it up. EditText stays behind the keyboard ( is hidden). Why is that? What I should do to lift the EditText above the keyboard. EditText is placed in LinearLayout and that all is placed in FrameLayout at the bottom. Thank you!
Edit (code of layout):
<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"
tools:context=".ProfileChooseActivity"
android:scrollIndicators="none"
android:background="#drawable/bg_run4">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<LinearLayout
android:orientation="vertical"
android:layout_width="233dp"
android:layout_height="159dp"
android:layout_gravity="start|bottom"
android:layout_margin="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/profileNameEditText"
android:layout_margin="10dp"
android:backgroundTint="#97f8720b"
android:hint="#string/profile_name"
android:textCursorDrawable="#null"
android:layout_marginTop="20dp"
android:textColor="#3d3131"
android:textAlignment="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/enter_profile"
android:id="#+id/enterProfileButton"
android:layout_gravity="center_horizontal"
android:background="#97f8720b"
android:singleLine="false"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</FrameLayout>
I replicated the layout file as you described and everything is working. May be there is a problem with your layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textAlignment="center"/>
</LinearLayout>
</FrameLayout>

Adapting component when virtual keyboard appears

I'm designing a simple login activity. I've used the following xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My application title"
android:textSize="30sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical"
android:layout_margin="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginTop="15dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Login"/>
</LinearLayout>
</LinearLayout>
And I've obtained this result:
But If the focus is on the first EditText I obtain this:
and If the focus is on the second EdiText the result is the follwoing:
Considering I've used the following line in the Manifest, for my activity:
android:windowSoftInputMode="adjustPan|adjustResize"
I want that when the virtual keyboard appears, the two edittext, the button and the textview are visible and correctly centered in the available screen.
What I have to change in my code?
NOTE: I've the same result If I remove the line in the manifest:
android:windowSoftInputMode="adjustPan|adjustResize"
You can replace the parent LinearLayout to a ScrollView :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout ...>
....
....
</LinearLayout>
</ScrollView>
try this, it works for some of my apk !
Edit : sorry didn't see about center the text automaticaly, so with this you can adjust manually your editext to center with swipe your finger.. hope that will help

Button at bottom disappears

There is a very high possibility that a question similar to this has been asked earlier, but I couldn't figure out the related keywords to find the same.
I am making an application, and the layout I designed is:
<LinearLayout 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Scheduler" >
<EditText
android:id="#+id/addressee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/addresseeHint"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<EditText
android:id="#+id/date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/scheduleDate"
android:inputType="date" />
<EditText
android:id="#+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/scheduleTime"
android:inputType="time" />
</LinearLayout>
<EditText
android:id="#+id/smsText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:hint="#string/smsTextHint"
android:inputType="text" />
<Button
android:id="#+id/scheduleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="#string/scheduleTextButton" />
</LinearLayout>
The layout which appears is as below:
What I want will look something like this:
The problem is the Button at the bottom (id:scheduleText) disappears, reason being the layout_height parameter of the EditText set just above it is fill_parent. But I guess I can't provide any particular value to it as then the layout will look different on different devices ?
How can I fix this bug ?
Thanks
Hi your EditText has a height of fill parent which makes it fill the parent and the button won't be visible so make it like this:
<EditText
android:id="#+id/smsText"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/smsTextHint"
android:inputType="text" />
UPDATE:
I updated the answer to extend the edit text and fill the screen but let space for the button as well. The trick is to use weight..

Categories

Resources