Issue with Edittext and softkeyboard - android

Having Problem with Edittext and SoftKeyboard.
now if i click on edittext(hello text) to modify it (means when it gains focus bottom gridview is poping up see second image)
so how to change this behaviour of poping up the bottom views?
Any Help will be greately appreciated.
Thanks in advance.

you can open dialog and in dialog add EditText and on ok button you can change that text according to text added in dialog edittext.

android:windowSoftInputMode="adjustResize" property might be squeezing your background
use android:windowSoftInputMode="stateVisible|adjustPan" instead.

View activityRootView;
activityRootView = (LinearLayout) findViewById(R.id.root); // main layout id
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
if (heightDiff > 100) {
// if more than 100 pixels, its
// hide your below layout like layout1.setVisibility(View.GONE);
} else {
// visible your below layout like layout1.setVisibility(View.VISIBLE);
}
}
});

Related

How to validate virtual keyboard visibility?

I want to show a button when the virtual keyboard is open and hide this button if the virtual keyboard visibility is off.But I could not find any listeners to perform this activity.
Anybody knows how to do this?
As found here, you'll need to instantiate the SoftkeyBoard and add a listener.
/*
Somewhere else in your code
*/
RelativeLayout mainLayout = findViewById(R.layout.main_layout); // You must use your root layout
InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
/*
Instantiate and pass a callback
*/
SoftKeyboard softKeyboard;
softKeyboard = new SoftKeyboard(mainLayout, im);
softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged()
{
#Override
public void onSoftKeyboardHide()
{
// Code here
}
#Override
public void onSoftKeyboardShow()
{
// Code here
}
});
/*
Open or close the soft keyboard programatically
*/
softKeyboard.openSoftKeyboard();
softKeyboard.closeSoftKeyboard();
/*
SoftKeyboard can catch keyboard events when an EditText gains focus and keyboard appears
*/
/* Prevent memory leaks:
*/
#Override
public void onDestroy()
{
super.onDestroy();
softKeyboard.unRegisterSoftKeyboardCallback();
}
In his post, you will also find more information about bug fixes and possible problems.
add onGlobalLayoutListener to your parent view of activity/fragment and make your button visibility accordingly
final View parentView= findViewById(R.id.myrootview);
parentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = root.getRootView().getHeight() - root.getHeight();
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
if(heightDiff <= contentViewTop){
//Soft KeyBoard Hidden---button visible
}else{
//Soft KeyBoard Shown---button hide
}
}
});
There is no direct event for keyboard open and close. but you can create observer on your full layout and then display buttons or whatever you want to do.
For Observer code check this - Hide part of activity_main.xml if keyboard is open (Android)

Keyboard placement obscures view below EditText would like to keep visible

I have an activity that is basically a long form of entry fields.
On each row, I want to show a TextView to serve as hint text just below each EditText and I want the TextView to remain visible at all times when the user is entering data. Unfortunately, the soft keyboard obscures the hint text and always positions itself immediately below the EditText. Is there any technique that will allow the TextView below the EditText to also be visible when the soft keyboard appears and the contents are adjusted (via windowSoftInputMode=adjustResize|adjustPan), without having the user scroll ?
Vishavjeet got me on the right track in suggesting I scrolldown to reveal the view that may be overlapped by the keyboard. Below is a function similar to what I used to solve the problem. It can be called when the EditText above the TextView receives focus:
// View targetView; // View that may be hidden by keyboard
// ScrollView scrollContainerView; // Scrollview containing hiddenView
//
void assureViewVisible (View targetView, ScrollView, scrollContainerView) {
Window rootWindow = activity.getWindow();
Rect rMyView = new Rect();
View rootview = rootWindow.getDecorView();
rootview.getWindowVisibleDisplayFrame(rMyView); // Area not taken up by keyboard
int subTextPos[] = new int[2];
targetView.getLocationInWindow(subTextPos); // Get position of targetView
int subTextHt = targetView.getHeight(); // Get bottom of target view
if ((subTextPos[1]+subTextHt) > rMyView.bottom) { // Is targetView at all obscured?
int scrollBy = (subTextPos[1]+subTextHt) - rMyView.bottom + 10; // add a small bottom margin
mMeasurementViewScrollView.smoothScrollBy(0, scrollBy); // Scroll to subtext
}
}
EDIT:
By understanding the problem more deeply, I think that you should add scroll programatically when user clicks on the Edittext. Here is the code to do that:
private final void focusOnView()
{
new Handler().post(new Runnable()
{
#Override
public void run()
{
your_scrollview.scrollTo(0, your_EditBox.getBottom());
}});
}
From my personal experience I think there is not such way to do that. The thing you can do is place the hint textview toRightOf the editext. Or Use modern Approach by using a Hint Placeholder on Edittext:
In XML, it's simply android:hint="someText"
Programatically you can use edittext.setHint(int);
pass R.string.somestring in above method.

Update parent of TextSwitcher when text changed

Im using a textSwither for hide/show a part of text like this way :
txtDescription.setInAnimation(in);
txtDescription.setOutAnimation(out);
txtDescription.setFactory(new ViewSwitcher.ViewFactory() {
#Override
public View makeView() {
TextView textView = new TextView(ShopContentDetailActivity.this);
textView.setTextColor(getResources().getColor(R.color.NightDark));
return textView;
}
});
And call this method for change text :
private void changeDescription() {
if (displayShort)
txtDescription.setText(Html.fromHtml(shortDescription));
else txtDescription.setText(fullDescription);
displayShort = !displayShort;
}
My problem is when user touch textSwitcher to display text and touch again to hide it ,the height of parent view (a linear layout ) of textSwitcher remain as when text is displayed and dont change its height.
How can i update the parent view when text change ? (its ok when touch for display full text)
I resolve my problem in this way : (I think TextSwutcher change visibility of TextViews to INVISIBLE not GONE then i use this trck)
private void changeDescription() {
if (displayShort) {
txtDescription.setCurrentText(null); // this line change invisible textView visible but without text and make it height 0 and then set the second textView text
txtDescription.setText(Html.fromHtml(shortDescription));
} else txtDescription.setText(shopContent.getDescription());
displayShort = !displayShort;
}
But there is a problem that is not so important for my case: when you hide a part of text its blink.
if i resolve it i will update my answer.

how to hide the footer fragment when keyboard appear

I have footer bar in my activity. I used fragment for footer bar. here is screen shot. . When I add the text into the EditText, the keyboard show like this. . I would like to hide the footer when the keyboard appear. I used android:windowSoftInputMode="adjustPan" in activity. I would like to know any suggestion.
Thanks.
i have faced same situation, and dont have finded any solution,so just started another activity on touch of textview. on completion of activity again in this activity gotted result back from the textview of next activity and placed the text in current activity's textview. it works
i got the same problem i just removed android:windowSoftInputMode="adjustPan" from my manifest file and i got the desired output
var originalHeight = document.documentElement.clientHeight;
var originalWidth = document.documentElement.clientWidth;
$(window).resize(function() {
// Control landscape/portrait mode switch
if (document.documentElement.clientHeight == originalWidth &&
document.documentElement.clientWidth == originalHeight) {
originalHeight = document.documentElement.clientHeight;
originalWidth = document.documentElement.clientWidth;
}`enter code here`
// Check if the available height is smaller (keyboard is shown) so we hide the footer.
if (document.documentElement.clientHeight < originalHeight) {
$('.footer').hide();
} else {
$('.footer').show();
}
});
try this it will work and give class="footer"

Showing dropdown of AutoComplete below

I have a layout in which I have autoComplete edit text with some suggestions.
The image below is its normal behaviour until keyboard slides in.
after the keyboard comes the dropdown goes above the field which hides my TO: field. As shown below.
What should I do to get the dropdown below even when the keyboard slides up.
I want the result to be like this.
Thanks...
I resolved this by hiding the upper layout when key board is shown and focus is on this edit text. As soon as the keyboard is slided_out the upper layout is visible again which bring back the original screen.
For detecting the keyboard slide_in/slide_out i used something like this.
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its
// probably a keyboard...
if (searchText.isFocused()) {
//keyboard is shown
}
} else {
if (searchText.isFocused()) {
//Keyboard is hidden.
}
}
}
});

Categories

Resources