AutoCompletTextView Covered by dropdown view - android

Opening dropdownView of autoCompleteTextView in ontouchlistener by calling
show DropDown but when its clicked DropDown opens. Then keyboard opens up, autoCompleteTextView moves up along with keyboard.
But dropdown view remains on its position when it was opened before opening of keyboard And before moving up of autoCompleteTextView due to keyboard opening.
happening is autoCompleteTextView gets covered by Dropdown View and remaining Dropdown view gets covered by keyboard.

try this for your activity in manifest.xml file:
android:windowSoftInputMode="stateHidden|adjustResize"
or
android:windowSoftInputMode="stateHidden|adjustPan"
The android:windowSoftInputMode attribute can be used to specify what happens on a per-activity basis: whether the layout is resized or whether it scrolls etc.
you can also hide the soft keyboard when spinner is touched:
mSpinner.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//here mEditText is your edittext where keyboard is shown before
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
return false;
}
}) ;

try the below code in mainfest
<activity
android:name=".activity name"
android:windowSoftInputMode="adjustPan" >
</activity>
and use this
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
in onCreate() of Activity

Related

how can full clear focus in editText , just like press button DONE on softkeyboard

I specify different backgrounds when edit text focus changed , but clearFocus() seem like no effect , because the background do not change to the right state .
Firstly, we can use cleareFocus method to remove the focus.
editTextView.clearFocus()
But when this method is called, as source code comment says:
When not in touch-mode, the framework will try to give focus to the first focusable View from the top after focus is cleared. Hence, if this
View is the first from the top that can take focus, then all callbacks
related to clearing focus will be invoked after which the framework will
give focus to this view.
so after you call it, the first element will stay get the focus. so we should set the touch-mode true in parent layout.
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<EditText android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Create one more EditText(edit_hidden) and set visibility GONE or INVISIBLE
When you want to clear Focus from your EditText(edit_your) then use this Code
edit_your.clearFocus();
edit_hidden.requestFocus();
Using Action Done Event
edit_your.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
edit_your.clearFocus();
edit_hidden.requestFocus();
}
return false;
}
});

How to hide keyboard when user clicks on textbox in webview android

Can we hide android system keyboard when user focuses or clicks on html input elements inside the webview.
I have tried hiding keyboard on user touches webview:
webView.setOnTouchListener(new View.OnTouchListener()
{
#Override
public boolean onTouch (View v, MotionEvent event){
Toast.makeText(cx,"Web View Touch",Toast.LENGTH_LONG).show();
v.onTouchEvent(event);
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
})
But that doesn't work.
Is there option to hide keyboard entirely for a app?
You can control the softkeyboard - Handling Input Method Visibility for each activity with the manifest like so:
<activity
android:name=".Main"
android:windowSoftInputMode="stateAlwaysHidden" >
<activity
android:name=".Main"
android:windowSoftInputMode="stateHidden" >
You can also control it so it flows using 'next' from one edittext to the next and then hides again with 'done' using IME options.
android:imeOptions="actionNext"
android:imeOptions="actionDone"
I also realise the problem would be with using a webview and needing to also disable any keyboard from parent layouts,as the webview is separate from the activities in the manifest, so add this to any parent layout:
android:descendantFocusability="blocksDescendants"
and in the webview:
android:focusable="false"
android:focusableInTouchMode="false"
try this in the activity in manifest.xml..
android:windowSoftInputMode="stateHidden"
it may help.

Prevent Softkeyboard from opening on EditText Focus

I need to prevent softkeyboard from showing up when Edit Text gains focus or if user taps on the edit text because user has to use a barcode scanner as an input method. But I need is open the keyboard when user clicks/taps a specific button.
I have tried focusableInTouchMode property and it works fine in preventing the softkeyboard from popping but it won't let the edit text gain focus.
Any hint on how to achieve this?
myEditText.setInputType(InputType.TYPE_NULL);
myEditText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// showMyDialog();
}
});
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// showMyDialog();
}
}
});
Try this.... Just return null or anything on onclicklistner..
Njoy.. :)
And m using it so don't tell me its not working.. LOL..
I have one condition that if user clicks on edittext then it ll pops DatePicker Dialog and its working.
So njoy dude...: ;)
you can hide the keyboard using this code
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You should use stateAlwaysHidded. Either in runtime as in the first answer, or directly in your project Manifest:
android:windowSoftInputMode="stateAlwaysHidden"
This will prevent keyboard from appearing during onCreate/onResume.
To prevent keyboard appearing after clicking EditText, you can place some blank view with transparent backround right on top of your EditText:
<View
android:id="#+id/view"
android:layout_width="editTextWidth"
android:layout_height="editTextWidth"
android:background="#android:color/transparent"
android:clickable="true"/>
The key attribute here is android:clickable="true". It will prevent from gaining focus on click (actually users will click on this blank view, not EditText).
Then, when user clicks special button you've mentioned, you just remove this blank view and call editText.requestFocus()

Software keyboard resizes background image

I have a layout like below :
<ScrollView ...>
<LinearLayout...>
<EditText
..../>
</LinearLayout>
</ScrollView>
As soon the fragment loads we set the focus of the EditText so that it displays Keyboard.
We have also set the background :
mParent = inflater.inflate(R.layout.sample_layout, container, false);
mParent.setBackgroundResource(R.drawable.sample_bg);
The issue is that when the keyboard is shown the background resizes or the keyboard pushes the background image up.
mEdTxt.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEdTxt, InputMethodManager.SHOW_IMPLICIT);
mEdTxt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
We have tried :
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I have seen many posts revelant to this but didnt help me.
EDIT : Question is not Duplicate
How ?
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
The above code will disable the scroller.
We need the keyboard to be shown also the scroller to be present so that the user can scroll the page when the keyboard is shown.
I hope its clear.
Sounds like you have in the Activity node in your Manifest:
android:windowSoftInputMode="adjustResize"
If you don't want it to resize, remove this or change it to something different.
http://developer.android.com/guide/topics/manifest/activity-element.html

Removing autofocus from EditText and regaining focus ?

I have an EditText and a set of Buttons in my layout.
To remove autofocus from EditText i am using a dummy LinearLayout as told in some answers at this site.
I want the edit text to get focus on button press and the virtual keyboard being shown.
but on 1st button press the edit text gets focus but virtual keyboard is shown only after button is pressed again.well the problem is bit different but any idea? This is what i m doing on button click:
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
mgr.showSoftInput(main_edt,InputMethodManager.SHOW_FORCED);
main_edt.requestFocus();
}
});
This is the dummy linear layout:
<LinearLayout
android:focusable="true"
android:id="#+id/dummyll"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px" />
If i dont write this dummy linear layout or make the focusable tags as false the keyboard shows on 1st click only.
Let's try to set the below properties in your xml itself for EditText
android:focusableInTouchMode="true"
android:cursorVisible="false".
I hope it may solve your problem,if you suppose want to hide the softkeypad itself at launching activity means use the below code in your activity
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Add attribute android:windowSoftInputMode="stateHidden" to the activity in your manifest. This way, the soft keyboard will no be shown, when you start the activity.

Categories

Resources