Softkeyboard not displaying in 2.2 landscape mode - android

I am facing a strange problem.
My app works fine in 2.1 (emulator + device). But, when I use 2.2
(both emulator + device) then there is an issue with the soft
keyboard.
There is a Activity in landscape mode in the app (use
android:screenOrientation="landscape").
There are two EditText in that Activity. But, soft keyboard is not
displaying for those. In fact, softkeyboard seems to apprear, but as a
bar in the bottom.
Please view the screenshot.
Any help will be appreciated.
Regards
Sarwar Erfan
tried different things for android:windowSoftInputMode , did not work
<Activity android:name=".PriceCalculator"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysVisible|adjustPan"
android:configChanges="orientation"
android:label="Pricing Calculator">
....
</Activity>
<EditText
android:id="#+id/adhesiveUnitPrice"
android:inputType="numberDecimal"
android:imeOptions="actionDone|flagNoExtractUi"
android:layout_column="4" android:gravity="right"/>

I found out that, in 2.3, the softkeyboard wont show up in landscape mode if the emulator or the device has an hardware keyboard.

I had a similar problem with my code (see example here bellow). FYI, replacing "InputMethodManager.SHOW_IMPLICIT" by "InputMethodManager.SHOW_FORCED" solved the issue.
public class Main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText et = (EditText)findViewById(R.id.et);
et.setFocusableInTouchMode(false);
final Context context = this;
et.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
v.requestFocusFromTouch();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
}
});
}
}

Related

How to disable the default keyboard in EditText, allowing the other actions

I have an EditText, since I use a custom keyboard in my App, I have disabled the standard android keyboard.
Unfortunately now seems that I cannot use the copy paste, selection etc when I click on the EditText in Jelly Bean, in Gingerbread my edit text has the desired behavior.
I need simply to disable the android keyboard to use my custom keyboard but the others copy-paste actions, selection etc, must be active
How could I fix this?
My EditText is this:
<EditText
android:id="#+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:autoText="false"
android:background="#color/light_sky"
android:cursorVisible="true"
android:editable="true"
android:gravity="left"
android:imeOptions="flagNoEnterAction|flagNoExtractUi"
android:scrollbars="none"
android:singleLine="true"
android:textSize="32dip" />
You proably have set a null input in your EditText.
If other situations you can prevent the keyboard showing simply using in the manifest
android:configChanges="orientation|keyboardHidden"
In this way the Android keyboard will not auto-open but is shown only if you click directly the EditText
Building on this topic https://stackoverflow.com/a/10636686/2558337 i suppose that you should #Override onClickListener
inputField.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
});
You could even try this that works
declare a InputMethodManager variable private InputMethodManager imm;
And in your onActivityCreated() method add these lines
// to hide the keypad
imm = (InputMethodManager) getActivity().getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0);
And to unhide use the following code
editText = (EditText) getView().findViewById(R.id.editText);
editText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
imm.showSoftInput(inputSearch, 0);
}
});

How to Hide keyboard when activity starts

I have an activity with lots of edittext. whenever I load that activity, the keyboard appears and eats half of the screen which makes that activity's look bad. So is there any way to hide keyboard when I load that activity.
in your onCreate() use this..
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Add this two line in your activity's XML file in the RootLayout i.e. either relative or linear(whatever you have taken) :
android:focusableInTouchMode="true"
Add this line in activity manifests file
android:windowSoftInputMode="stateHidden"
In your AndroidManifest.xml add the attribute android:windowSoftInputMode:
<activity android:name="your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
You can do this using intputmethodmangare... using the following code..
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Put this code on the onCrete function:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
view.clearFocus();
}}, 50);
where view is your EditText
The runnable is because the code might be executed before the editText is rendered.
I created a method which I call in all the required Activity classes in the onCreate event. Worked for me in all scenarios.
public class ClassLib {
public static void hideKeyboard(Activity activity) {
//Hide keyboard
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}

Android: softkeyboard not showing up

I have 2 EditTexts in the MainActivity Layout. If i run the application normally the 1st EditText gets focused but the softkeyboard is not openned.
but when i used this:
public class TestingActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText et1 = (EditText) findViewById(R.id.editText1);
EditText et2 = (EditText) findViewById(R.id.editText2);
et2.requestFocus();
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.showSoftInput(et2, InputMethodManager.SHOW_IMPLICIT);
}
}
expecting the 2nd EditText will get focus and softkeyboard will be openned.
I only get focus, but the softkeyboard is openned only when i click on the EditText.
Thank You
Try specifying the android:windowSoftInputMode attribute in your AndroidManifest.xml file for your activity.
For example:
<activity android:name=".TestingActivity" android:windowSoftInputMode="stateVisible|adjustResize" />
You probably don't need any of the code that uses InputMethodManager in your Activity.
I notice that one reason for the keyboard not showing up is selecting an inputtype not supported by the specific Android device. For instance InputType.TYPE_NUMBER_VARIATION_NORMAL will not work on my Asus Transformer (no keyboard shows up), while InputType.TYPE_CLASS_NUMBER will work just fine.
et2.clearFocus();
et2.requestFocus();
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.showSoftInput(et2, InputMethodManager.SHOW_IMPLICIT);
I meet the problem on Android N platform and resolve it by refocusing the editview.
I don`t know the real reason why the editview should be cleared first,but it works fine for me.
Sometimes you will need to post-delay showing keyboard command, so in my case, i did the following
editText.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
}, 300);
For getting the focus to particular edittext just add the tag inside your edit text.
<EditText
android:id="#+id/etBox"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="enter into editbox"
>
<requestFocus/>
</EditText>

Soft keyboard not showing up at program startup

I've browsed similar questions and followed the suggestions there, but for the love of god, I can't get this to work, and it's driving me crazy. So here's the deal:
I have an editText, which needs to requestFocus at program startup, and pop the soft keyboard. If I put "android:windowSoftInputMode="stateVisible" in the Manifest, the keboard shows every time the activity starts. I only want it to show once with onCreate(), and when the user specifically clicks on the editText. My code for this is below:
EditText argument;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_buttons);
argument = (EditText) findViewById(R.id.editText_argument);
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(argument, InputMethodManager.SHOW_FORCED);
Q1) This code doesn't work. What am I doing wrong?
Q2) You see that I declared "EditText argument" outside of onCreate(), as I'd like to use this in the rest of the activity, not just within onCreate(). Is this good programming practice?
Q3) Then, when the user clicks done on the soft keyboard, I'd like this EditText to lose focus, i.e. the cursor should disappear. I understand that I need to have a dummy View to do this, but I still don't exactly understand how to switch focus to the dummy. How would I go about doing that?
Thanks so much in advance!
A1) You're missing a editText.requestFocus().
Refer: Soft Keyboard shows up on EditText focus ONLY once should help for dismissing soft keyboard.
A2) Yes, that's fine. Most of the UI elments should be declared at the class level scope and initialized in onCreate()
A3) A1's reference link should help you here.
Happy Coding!
EDIT:
onCreate():
EditText argument;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_buttons);
argument = (EditText) findViewById(R.id.editText_argument);
showKeyboard():
argument.requestFocus();
argument.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(argument, 0);
}
},200);
dismissKeyboard():
argument.requestFocus();
argument.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.hideSoftInputFromWindow(argument.getWindowToken(), 0);
}
},200);

How do specify which EditText should get focus on Activity starts and auto bring up keyboard?

I want to immediately highlight give focus to a particular edit box when the activity loads and bring up the softkeyboard. how can I do this? Also should there be anything in onStart()?
You can call : requestFocus() on the View after you do findViewByID()
You can do that in onStart - I see now reason for it not to work.
Check here too :
http://developer.android.com/reference/android/view/View.html
In your layout put </requestFocus> tag inside EditText.
In onStart() call
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Ideally this should work.
<EditText
android:id="#+id/Abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
But there have been some known issues of the keyboard not popping up. See this.
You can also do this using Runnable:
public class MyActivity extends Activity {
private Handler mHandler= new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get text
mHandler.post(new Runnable() {
public void run() {
text.requestFocus();
}
});
}
}
Using the getSystemService(...), one can obtain, in this case, the Context.INPUT_METHOD_SERVICE, have a look at this code sample below for illustration:
InputMethodManager imm = (InputMethodManager)context.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edittext, 0, null);

Categories

Resources