Android: Fixed Number Pad - android

I have an EditText and when clicked a numberpad slides up via android:inputType="number". When this happens though it pushes the TextViews above off of the screen. I was wondering if there was a way for the numberpad to always be shown (then I can have fixed positions for everything)?
(I do not have a lot on the activity, so it is not like I am trying to save space.) I want the user to be able to see the TextViews that get pushed off the screen because they are updated based on the input. Here is what it looks like:
<RelativeLayout 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=".Name" >
// TextViews that get pushed off
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="71dp"
android:layout_toLeftOf="#+id/enter_input"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
</RelativeLayout>
Is this possible? Or is there a better way so everything is shown on the screen and so nothing is hidden?

You can add android:windowSoftInputMode="stateAlwaysVisible" to your activity in AndroidManifest.xml so it forces the keyboard to always show.
<activity android:name="[activity_path]" android:windowSoftInputMode="stateAlwaysVisible"/>

Related

Android soft keyboard hides controls

I know there are lots of questions about this but none of the answers are working for me. Here's a screen in question before opening the keyboard.
Here's the screen after opening the keyboard by tapping on an EditText, and then scrolling as far down as possible.
Note that besides the final edit control being mostly concealed, all the text and the button after it are inaccessible.
Here's the fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:validator="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:background="#color/background">
<TextView android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary"
android:text="#string/help_header"
android:textSize="20sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
/>
<TextView android:id="#+id/drop"
android:layout_below="#id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_sub_header"
android:textSize="16sp"
android:textColor="#color/material_drawer_secondary_text"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
/>
<View android:id="#+id/divider1"
android:layout_below="#id/drop"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_gray_background"
android:layout_marginBottom="#dimen/activity_vertical_margin"/>
<LinearLayout android:id="#+id/linear1"
android:layout_below="#id/divider1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<!-- Several EditTexts and such -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
It was originally in a LinearLayout and I changed it to a RelativeLayout based on a suggestion, but that didn't change anything. I have also played with the layout height (wrap_content / match_parent) of the top two levels of view groups to no effect. Here is the activity declaration in the manifest:
<activity
android:name=".MainActivity"
android:label="#string/application_name"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I've also tried adjustPan and it doesn't seem to change. I'm not too concerned about what exactly the UI elements do when the keyboard opens, I just want the whole layout to be accessible by scrolling.
Basically everyone points to the soft input mode, but that doesn't seem to be doing anything. Is there something about fragments that I'm missing? Or maybe this is harder than I'm expecting and I need to make a custom layout class and measure the layout and nasty stuff like that? I can add the activity layout though there's not much to it, or code such as the fragment creation/transaction stuff.
THat's what the keyboard does. It covers the bottom of the screen. If you want it to not cover your app at all, you can use adjustResize. That will scale your app to only draw in the top half. But if your content is too big it still won't fit and it will look as if your app is covered (even though it isn't. Scrolling it via a scroll view should work then (although I've never actually tried it). But the only thing you can do to control the behavior when the keyboard is up is the softInputMode.
If you have lots of adjustable space or whitespace, there are techniques that will shrink you somewhat and may allow your full app to appear in the reduced space. This isn't the case here, you have too much stuff on screen (except for maybe on a tablet in portrait mode). So they aren't going to apply here.
It turns out the problem was with a library, material-drawer (nice library). For anyone else encountering this:
https://github.com/mikepenz/MaterialDrawer/blob/master/README.md#i-have-problems-with-the-softkeyboard-how-can-i-fix-this
Call Drawer.keyboardSupportEnabled(this,true) and the layout will arrange and scroll appropriately.

Android Full Screen resize when soft input is shown

I am developing an Android app in full screen mode. I want the screen automatically adjusted when a soft input is shown. I am using ScrollView to make my screen can extend larger than the maximum height. You can see the layout XML below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}" >
<VideoView
android:id="#+id/taskdetail_bgvideo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Other Widgets -->
</LinearLayout>
</ScrollView>
</RelativeLayout>
The VideoView in the background is placed as intended to create a background video in the overall layout.
I tried the workaround in Android How to adjust layout in Full Screen Mode when softkeyboard is visible but somehow in my case, it doesn't work as expected. When I choose the bottommost TextView, all screen somehow pushed upwards to the top, leaving a very big black area between soft keyboard and the activity screen. Check the screenshot below (Sorry, still low reputation, so cannot post the image directly :( )
Giant blackhole
So do you have any possible idea to tackle this weird behavior? In addition, I also have tried setting the softInputMode to ADJUST_RESIZE or ADJUST_PAN, and both settings did that. When I set it to ADJUST_NOTHING, nothing really adjusted at all.
When I don't use the workaround I mentioned above, I cannot scroll the view to the bottommost widget, but somehow the window view is panned to the focused TextView. I believe that this is actually the major culprit, but I don't know how to fix it.
Thanks in advance :)
If you have the property <item name="windowFullscreen">true</item> in your theme then the android:windowSoftInputMode="adjustResize" doesn't work.
Try change
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
to
<ScrollView
android:id="#+id/taskdetail_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent" >
you have to write
android:windowSoftInputMode="stateHidden|adjustPan"
in your manifest file
Try to add below properties to your <activity tag declaration in AndroidManifest.xml
android:windowSoftInputMode="stateHidden|adjustPan"

EditText not showing up when Activity holds multiple fragments

For the few people looking at my previous similar question, I deleted it and moved it here to be a more specific question now that I have a greater insight to the problem.
I have an Activity that holds one fragment on my standard phone, and holds two fragments on larger devices (tablets). The Activity holds the options menu, as well as the EditText. When I use my phone, everything loads fine. When I use my tablet, the EditText is not shown in the Activity. Here is the .xml files.
Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xlmns:tools="http://schemas.android.com/tools
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="8dp"
android:orientation="vertical" >
<EditText
android:id="#+id/trips_editText_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/searchClients"
android:inputType="text|textNoSuggestions"
android:visibility="visible" >
<requestFocus />
</EditText>
<fragment
android:id="#+id/trips_list"
android:name="com.ib.dfm.TripsListFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:context=".TripsListActivity"
android:layout="#layout/trip_list_item" />
</LinearLayout>
Can anyone figure out why the EditText will not show up on my tablet? Also, if I try and access it programatically with findViewById I get null. Thanks.
You most likely have multiple layouts defined for your Activity and with tablet the xml file does not contain the EditText
You use fill_parent which has become deprecated, use match_parent instead. Hope it helps.

Soft-keyboard appears every time layout becomes visible

I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa. When the layout that contains an EditText becomes visible the soft keyboard automatically pops up. I have used the following in the manifest but it didn't help.
android:windowSoftInputMode="stateUnchanged"
I never explicitly request focus on the EditText and have even tried requesting focus on something else to no avail.
<?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:id="#+id/container">
<LinearLayout android:id="#+id/dial_pad_ll"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:layout_centerInParent="true"
android:background="#1E1E1E" android:layout_marginLeft="20dp" android:layout_marginRight="20dp">
<EditText android:layout_height="wrap_content" android:id="#+id/search_et"
android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_marginTop="20dp" android:layout_marginBottom="10dp" >
</EditText>
<!-- Other widgets here -->
</LinearLayout>
<!-- Other Layout Here -->
</RelativeLayout>
Anyone know how to prevent this? Thanks.
Edit: I should also have mentioned that this doesn't happen the first time. I open layout 1 with the edit text, make it invisible, make it visible again, then the keyboard pops up.
try adding this to your activity.
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Buggy ListView makes me sad

I have a ListView where I've defined the layout of each item in a separate XML file. In this file I've included a RatingBar and an EditText.
I've programmatically created 7-8 items in this ListView. When I scroll through them, it seems to be quite buggy. Here are some examples:
If I set focus to the EditText in the first row and then scroll down the ListView, random EditTexts from other rows will have focus. It seems to be that the next EditText after the focused one disappears receives focus. Perhaps this is intentional, but, as a user, it seems very weird.
If I set focus to an EditText, receive a virtual keyboard, type something, and click the "Done" button on my virtual keyboard, the EditText will empty as soon as the virtual keyboard disappears.
Sometimes, when I click an EditText, receive a virtual keyboard and start typing letters, the letters will disappear as soon as I type them.
When I click on an EditText, the virtual keyboard shows itself, but the EditText loses focus and I have to click the EditText again.
Even though I've set the RatingBar to focusable="false", if I move my scrollwheel, it still grabs focus.
One of my problems is all the visible list items get redrawn when I type a character in the virtual keyboard (and since the text of the EditText is set to some data, which is empty, it gets cleared. I don't understand why Android would decide to redraw the list every time I type a character.
Here is the XML I'm using to draw them. They are white bubbles, with a gray boarder, and some text, a RatingBar and an EditText inside:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="#drawable/shape_outer">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="#drawable/shape_inner">
<TextView
android:id="#+id/rating_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/dark_gray"
android:textStyle="bold"
android:layout_marginBottom="10dip" />
<RatingBar
android:id="#+id/rating_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="0"
android:stepSize="1"
android:focusable="false"
android:clickable="false"
/>
<EditText
android:id="#+id/rating_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:padding="6dip"
android:textColor="#000000"
android:gravity="left|top"
android:lines="3"
android:hint="Comment"
android:imeOptions="actionDone" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
It sounds like ListViews aren't able to handle EditTexts well. I've done some research and the consensus seems to be "don't do that." So what I've resorted to is creating a simple layout file which is a ScrollView with a LinearLayout inside. In my onCreate method, I inflate the View I was using for my list item and add it to the LinearLayout. I'm also adding the View to an ArrayList so I can save the data in each View later on.
Does this sound reasonable?
Well,add this to your activity in manifest...
android:windowSoftInputMode="adjustPan"
Example...
<activity android:name=".mapview.AddParkingLotActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/>
I was having the same problem. My EditText inside of LisView was losing focus when the keyboard appears, so on getView from the ListView item I put
final EditText editInput = (EditText)convertView.findViewById(R.id.edit_input);
editInput.requestFocusFromTouch();
And this work for me.
These two steps resolved a similar issue I had (EditText on a row within ListView + funny keyboard behavior).
Add android:windowSoftInputMode="adjustPan" attribute into
AndroidManifest.xml file on the activity where the ListView is
presented.
Add android:descendantFocusability="afterDescendants" attribute onto the ListView itself.
This is the actual example:
AndroidManifest.xml
<activity
android:name=".SubscriptionListActivity"
android:windowSoftInputMode="adjustPan"
android:label="#string/title_activity_subscriptions" >
</activity>
layout.xml file
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:id="#+id/subscriptionList" />
I tested it on Samsung Galaxy S3 and it works fine with Samsung as well as SwiftKey keyboards.
i have some issue i solved just commenting this line
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Categories

Resources