Attaching custom view to the top of Android keyboard - android

What is the simplest way to attach a layout defined in xml at the top of Android soft keyboard.
This view should only appear when the keyboard appears.

I think the best way is to detect when the keyboard appears and then attach view to the bottom of the screen (it will be above the keyboard after resizing all layout).

I think the cleaner way to do this.
Define a layout resource file to use as your custom view
Create a method which inflates this layout resource file and return it as a view:
Code Snippet
public View returnPayKeyView(){
View simpleView = getLayoutInflater().inflate(R.layout.simpleresource,null);
return simpleView;
}
Set this returned view as the candidates using the setCandidatesView Method
The returned view will show above your keyboard, using the inflated xml layout resource.

One approach is to wrap your usual view layout in a FrameLayout and put the bit you want above the keyboard inside the frame along with your other view layout with a layout gravity of bottom.
My layout was along these lines:
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- all your stuff... -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/stuffAboveKeyboardLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:background="#DDD">
<!-- stuff above keyboard... -->
</LinearLayout>
</FrameLayout>
The downside is that it will show even when the keyboard is hidden - but it ought to be possible to show / hide the view when the keyboard shows / hides: How do I Detect if Software Keyboard is Visible on Android Device?

Related

Visibility of Gone takes still space of particular control in android?

I am using the LinearLayout and inside there's button I am making visibilty gone based on supported states. SupportedStatuses are true then making Button as Visible but SupprtedStatuse are false then making button as Gone.
This is in a header and Button is Gone but still takes up the space.
Here is the Layout which I am using.
<LinearLayout
android:id="#+id/llparentView"
android:layout_width="match_parent"
android:layout_height="wrap_content
android:orientation="vertical">
<Button
android:id="#+id/btn_change_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Anybody have a good solution then it helps me a lot.
You could use a FrameLayout around whatever layout you are using
For example:
<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<!-- put your views here -->
</FrameLayout>
This will ensure when using View.GONE the FrameLayout collapses on the space.
Try to wrap your button in another Linear/Frame layout and change their visibility as well.

android: using adjustPan and without scrolling the title bar

I'm using android:windowSoftInputMode="adjustPan" in my manifest.xml.
It's doing me the job just fine but there is something retarded about it.
when i focus an EditText view that's, say in the bottom half of the screen, the title bar is also scrolled with the content of the activity.
image here
all i want is to freeze/float the title bar in place when scrolling the content. just like this:
image here
and no, I don't want to use adjustResize It overlaps views on top of each other
any help is greatly appreciated, been looking for the answer for a long time.
Found it!
Simply changing the root view in the layout xml file to a ScrollView does the job.
I don't even need to specify android:windowSoftInputMode
Of course I have to have everything else in a single layout as the child of the ScrollView
Edit
your .xml file should look like this:
<?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"
... >
<LinearLayout> // could be any other layout but linear works well here
//insert all other views of the activity here
</LinearLayout>
</ScrollView>
The answer suggested by Ace is essentially what is needed. My answer just aims to make things a little clearer.
There are two things you need to do. Firstly in the Manifest set the following on the activity. android:windowSoftInputMode="adjustResize"
Then, in the activity's layout you'll want to set a ScrollView beneath the Toolbar/Title Bar, as shown in the code below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
.../>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
From what I understand, here's how it works.
When you open the soft keyboard on your device, it will 'adjustResize' the layout of the activity. As the layout sits in a ScrollView, this is the part which is resized, and made smaller. Therefore the Toolbar/Titlebar will stay in place and the layout in the ScrollView will be scrollable when the keyboard is shown.

Slidedown a new layout from top

I have a main layout being hosted by an activity (setContentView method).
I have a button in the layout. I want to be able to click this button and a new layout will slide down from the left/top until the middle of the screen. So, the screen now will have two layouts where one is on top and another one is just beneath it.
This is something like the UI in Android Jelly Bean where you can pull the settings layout down using a touch gesture.
What are the possible implementations?
A method I have tried:
add the slide down layout into main.xml but set its visibility to gone
when button is clicked, run some code that will set the layout visibility to
VISIBLE and add some animations.
the result of this implementation is that this layout will push the rest of the
views down in order to have a "squeeze" space for itself which is not
what I intended to do (see above)
<?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:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/PR_slidedown" <---this is the intended slidedown layout
android:layout_width="8dp"
android:layout_height="40dp"
android:visibility="gone"
android:orientation="vertical" >
</LinearLayout>
....
Your implementation is partially correct, the other part is to host your two layouts in a FrameLayout so they can overlap with each other. Search for FrameLayout in here, there are a lot of example on how to use it.
Or try the SlidingDrawer

Android: Allow scrolling form with adjustPan

I'm working on an Android app with a slightly complex layout and I'm having nightmares to make it work the way I want.
My main layout is defined like this:
<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"
android:background="#000000"
tools:context=".MainLayout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none" />
<LinearLayout
android:id="#+id/menudown"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
... buttons ...
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true" >
... header content ...
</LinearLayout>
</RelativeLayout>
The idea of the layout is having a content frame(content), a footer menu (menudown) and a header (header) hovering over the content, aligned to the top of the screen. - Sorry guys, no image, confidential project.
The content is inflated with other layouts, depending on the section the user is, and some of them are forms to be filled. So, i just used the adjustPan and everything worked fine.
The problem here is: the client asked me to make the content scrollable while there's a soft keyboard showing, so that the user can view whatever he wrote on the other fields.
And it's painful because: the form fits the screen, so using content as a scrollview won't help, unless it gets resized.
And simply changing to adjustResize does not work because: the menudown goes up with the soft keyboard, which should not heappen. Also, the visual effect is terrible.
The app was already made for iPad (by someone else), and what heappens there is: the menudown remains aligned to the bottom of the screen, under the soft keyboard, which pushes only the content view up. Then, the content becomes scrollable, so that the user is able to see it entirely.
I have this same issue too, making keyboard behave the same way as it does on iOS. The best thing I can get from all the other posts is manually detecting the soft keyboard and moving the view up the difference.
This seems to be the best: How to check visibility of software keyboard in Android?

How to disable any event on a View in Android?

My question is simple: How to disable any event on a View in Android? (including removing its focussability, like I just want it to be there visually but be inexistant on everything else)
And does it work on a whole view tree? (like if I disable events on the root, all the events will be disabled for its children?).
Now, before you say anything I have tried all the following:
setEnabled
setFocusable
setSelected
setClickable
setActivated
And none of these methods appear to work, seriously.
I have tried them directly on a WebView, as well as on the parent layout on everything but I am still able to interact with it.
Any idea?
Thanks!
EDIT#1
The solution that consists in adding a view on top of the view that needs to be disabled doesn't work. Actually, it's still possible to click on the inner view, I have tried with a simple example:
<?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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Click Me!"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
/>
</FrameLayout>
Here it's still possible to click on the button.
EDIT#2
The reason why I want to do this is related to the following question that I asked weeks ago.
What I have is a ListViewacting as a navigation bar which is underneath a View that holds the content of my app. The problem with this implementation is that when I try to scroll through the ListView when there is a focusable view in the layer on top of it, well the ListView doesn't scroll and instead it's the top view that takes focus (That's the case when there is a
Webview or an EditText etc.).
So yes as mentioned in one of the answers, I can disable any click events on a WebView by overriding setOnTouchListener but the view remains focussed and I think this is the reason why I am still having the same issue with my navigation bar.
Simply put a view on top of your view. You can toggle it on off by setting view.visibility = gone/visible.
<FrameLayout>
<WebView/>
<FrameLayout This view will be on top/>
</FrameLayout>
Edit: Just stumpled upon this link: https://stackoverflow.com/a/3856199/969325
Basically disables all touch event for the webview. Tryed that?
Edit 2 reedit: Try to set the visibility to gone for the the top view below your listview.

Categories

Resources