Currently, when I build a popup all the view in the activity are blocked (blacked), it's normal.
But i want to allow 1 view (FloatingActionButton) to be accessible (so not blacked). Do you have some ideas ?
Thanks for your propositions !
Popup dialog takes all the screen as a normal behaviour and the Activity/Fragment layout behind gets unfocused... go for a Visibility trick to achieve that.
Make a layout using Relative layout and place a "dialog style" relative layout in front of everything else and set Visibility.VISIBLE when the user touch a button (or any other action) and Visibility.GONE to remove it from the view. (also, use setEnabled(false) to make sure non of the options inside that layout trigger a listener).
Anyway... all this goes against the UI/UX normal behaviour for users, I shouldn’t recommended you to go that way.
What is THAT important inside the FAB to left it available? Popup dialogs are for "YES/NO", "OK" options (mostly)
Related
Anyone help to add DONE button on top of soft keyboard like above screenshot shows.
Because I need Enter and Done both button on my Edit Text.
So, please suggest me If anyone have Idea.
Thanks in Advance...
How about just adding a custom Button in the bottom of your UI?
You can observe layout size changes -> find a case when keyboard appears and disappears (Remember its different case from screen rotation, different screen proportion)
Based on keyboard hidden/shown event you can show/hide your custom UI.
I guess only problem is, you don't know what is keyboard view background. But its definitely better than writting your own keyboard, AFAIK you can't add views to keyboards.
You have to create a custom keyboard for that. For custom keyboard you can try here:
https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615
https://developer.android.com/guide/topics/text/creating-input-method.html
https://inducesmile.com/android/how-to-create-an-android-custom-keyboard-application/
http://www.blackcj.com/blog/2016/03/30/building-a-custom-android-keyboard/
You would like to have an easy solution? Then integrate your "Done" button in your layout. Your layout should look like this (short version):
<LinearLayout orientation="vertical">
<ScrollView layout_weight="1"> <-- if needed, use FrameLayout else
place your Layout here
</ScrollView>
<YourDoneButton/>
</LinearLayout>
Your Button will stack on the top of the keyboard. I assume, that the user should be able to click of the "Done" button even if the keyboard is hidden. If not, you can hide it if your EditText is not focused.
i have an activity with an edit box, when the user touches inside the edit box, the soft keyboard comes up. if the user presses the hardware "back" button, the soft keyboard goes away. I want to detect this situation. I have looked around and the best response i've seen so far is this one:
http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782
my question is -- how can you detect if your application window has been resized?
I added this text to my activities in my android manifest file:
android:windowSoftInputMode="adjustResize"
but I'm not quite sure how to detect the change.
any help greatly appreciated.
Android does not provide an API for checking if the keyboard is visible or not. You can, however, key off the height of your top level layout to determine this information.
First, you have to set your activity's android:windowSoftInputMode attribute to "adjustResize".
Then, create a new class that extends your desired layout type (eg LinearLayout). In that class, you can override a few different methods that will be called as the height of your layout changes (due to the keyboard being shown or hidden). When these calls are triggered, you can compare the height of your layout to the height of the screen. If there's a substantial difference between the two (ie more than just the size of the notification bar), the keyboard is visible.
Finally, make sure that you use your new class as the top level layout in your layout xml (eg in place of LinearLayout).
If you would like a more thorough explanation, I've written one up: http://www.cannedcoding.com/2011/08/soft-keyboard.html
Creating an Input Method Service (See http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html) to listen for the back button might work. When it is pressed, you can pass that on to your activity which then does what you want it to do along with removing the soft keyboard.
I will start off with a bit of introduction as to what I desire my application to look like.
http://img806.imageshack.us/i/whatiwant.jpg/
I have been able to achieve that button bar and ImageView in the same layout using RelativeLayout.
Now my problem is that I want to know of a method to display that window/popup/dialog that appears after I press button 1.
What do I want with that window that spawns:
1. It should have a semi-transparent background.
2. It should close itself when focus is lost from it
3. Should have buttons and action listeners which can trigger events in the main application.
I have been looking over Android. PopupWindow but I was facing a lot of problems getting help about it i.e. It's action listeners, dismissal etc. So I dropped the idea.
For now I am working with dialogs. So far I have only been able to display a dialog. Problems
1. Custom Height and Width properties are not working for some reason (implemented using Layout Params)
2. How to have a Semi transparent background?
3. How to dismiss/hide the dialog when the focus is lost?
My question is,are there any better ways to do this besides dialogs? If so, please tell me what they are. If using dialogs is the way to go, how should I go about solving the aforementioned problems?
Any help would be appreciated.
Thank you.
PopupWindow is a better option. Check the AutoCompleteTextView for PopupWindow example.
To create the PopupWindow use
PopupWindow myWindow = new PopupWindow( content_view, width, height, true )
Use DismissListener, if you want to do anything when popupWindow is dismissed.
Also action listeners are independent of the PopupWindow i.e. if you have a button in content_view then you can set the onClick listener the same way you set it in normal case.
You should set the PopupWindow background, otherwise pressing back button won't dismiss it.
HTH !
My idea would be:
Make the "dialog" an element of the layout, but initially with android:visibility = "gone". Make sure to put it as the last element in the RelativeLayout so that it is above all the other layout elements (z-ordering).
In the onClick method for Button 1, toggle the visibility to "visible".
In the OnFocusChangeListener for the view, toggle it back to "gone" in the onFocusChange(View v, boolean hasFocus) method whenever hasFocus is false.
EDIT: To make the dialog an element of the layout, you would do something like:
<RelativeLayout>
<!-- Your other layout items here -->
<LinearLayout
android:id="#+dialoglayout"
android:layout_alignBelow="#id/yourbuttonbarlayout
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
<!-- Your dialog elements here -->
</LinearLayout>
</RelativeLayout>
Make sure to give your button bar layout an id (I've assumed yourbuttonbarlayout for the id. If you want three such dialogs, you can give them all the same layout parameters and toggle the individual visibilities. They can all show up in the same spot.
You can always use a background for the layout to simulate borders.
I have a layout which has one large EditText view at the top + a bunch of buttons at the bottom. The EditText is made to shrink and expand when the ime is activated/deactivated by using adjust_resize. The buttons at the bottom are pushed up above the ime.
I would like to hide these buttons when the ime displays, to provide enough space for the EditText view.
I have so far tried the following:
subclassed EditText and provided the activity the option to register a callback on the view's OnSizeChanged.
Used this callback to change the visibility of the buttons (actually the layout container) to GONE.
This work OK and does hide the buttons when the ime pops up.
However, the EditText does not expand into the new available space.
Furthermore, when the ime is disposed off, the EditText field is now bigger than it was originally, pushing (the now showing) buttons outside the screen.
I should also add that when typing the first letter into the view, and the ime displays the word options, the screen is redrawn and the EditText fills the vacant space.
Any ideas on how to get this to work?
Or even better, is there a simpler solution to my requirement?
Thanks...
NB: In my view, scrolling is not a good option.
I got this to work by changing the above method a bit:
Wrapped the entire layout with a FrameLayout
subclassed the FrameLayout and provided the activity the option to register a callback on the layout's OnMeasure
This gives the activity a chance to change visibility of views before these are measured.
I would still be very happy to hear about simpler solutions, especially in regards to figuring out whether the keyboard is currently visible or not.
(dumpsys window shows this information. Can we easily get to it?)
Have you tried to call myView.invalidade() ?
I was using the GONE property, but then changed to button.setVisibility(View.INVISIBLE); because I don't have any other stuff on my screen.
on the adjust_resize, you will need to check again when the keyboard has gone and show the buttons again.
In my android application, I have an EditText. When I click in this field, the soft keyboard appears, expanding from the bottom of the screen. It seems to actually modify my layout, pushing contents upwards. When I dismiss the keypad, it retracts, and I see my layout re-expand to take up the space it previously occupied.
Is there a way to get the keyboard to simply appear "on top" of my layout, so that I don't get this somewhat unpleasant relayout animation? The EditText is pinned to the very top of the screen, so I don't have to worry about the keypad hiding it.
Thanks
By default, Android should be using "Pan and Scan", which would work more or less how you described. The keyboard is displayed over your view, and you can scroll your view in the background. If you override the windowInputMode for you Activity, or Android determines that your Activity is resizable (because of the presence of a resizable field... ListView, ScrollViews, etc), it may resize your view instead, and it sounds like that's what you're running into. To force it to Pan and Scan try adding:
android:windowSoftInputMode="adjustPan"
as an attribute to the Activity element in your xml layout.
There's a third option as well. You can specify that when an EditText is selected it will be edited in full screen mode. The other controls in your view will be hidden, the user will be presented with just the keyboard, an EditText control, and optionally some other limited controls. If your EditText doesn't require a lot of context from other elements of your view, it may prevent a cleaner user interface. For more details, see: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
Add:
android:windowSoftInputMode="adjustResize"
to your activity attr in manifest.xml. Hope it will help.
This questions seems to state a resize is not desirable. I had the same issue, but adding
android:windowSoftInputMode="adjustNothing"
to the manifest file instead solved my problem.