Opening keyboard automatically when starting activity with dialog - android

I created a shortcut which its intent starts an Activity.
In the activity onCreate I show a android.app.Dialog with custom view.
I want to open the keyboard together with the activity/dialog.
The dialog layout:
<EditText
android:id="#+id/reminderEditText"
android:inputType="text"
android:maxLength="60"
android:maxLines="1"
android:hint="#string/remind_to"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
The activity declaration in manifest:
<activity
android:name=".ReminderActivity"
android:windowSoftInputMode="stateAlwaysVisible"
android:label="#string/new_reminder"
android:exported="true"
android:theme="#android:style/Theme.Translucent.NoTitleBar"/>
Activity onCreate():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.dialog_reminder, null);
EditText editText = view.findViewById(R.id.reminderEditText);
editText.requestFocus();
MaterialStyledDialog dialog = new MaterialStyledDialog.Builder(this)
.setIcon(R.drawable.ic_post_it_2)
.setCustomView(view, 20, 20, 20, 0)
.setPositiveText(android.R.string.ok)
.autoDismiss(true) // close dialog on callbakcs
.setCancelable(false) // not cancellable on outside touch
.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
As you can see I've tried every solution I could find online regarding displaying keyboard automatically and yet, no success.
I've also tried the suggested solutions in this question but non of them worked.

please try this:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

Try this,
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}

Related

Change keyboard's text pad with number pad

I have EditText and input type is textNoSuggestions.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name"
android:inputType="textNoSuggestions" />
</android.support.design.widget.TextInputLayout>
Also i have one button and in button onclick method i try to change keyboard's input type.This is a source
final Button changeKeyboard = (Button) dialog.findViewById(R.id.change_keyboard);
changeKeyboard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER);
}
});
Is it a possible to change keyboards' input type in button click when keyboard is showing?
How i can solve my problem thanks everyone
set is setTransformationMethod(), not setInputType(). So something like:
firstName.setTransformationMethod(numberTransformationMethod.getInstance());
On your code, change:
firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER);
to this (firstName with "t", the name on your xml):
firstName.setRawInputType(InputType.TYPE_CLASS_NUMBER);
Also, you positively can change your keyboard calling setInputType, like this: firstName.setInputType(x), where x is an int and can be 1 (alfanumeric); 2 (numeric) or 3 (phone like).
EDIT:
You can hide your keyboard calling this on your activity:
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
firsName.setInputType(InputType.TYPE_CLASS_NUMBER);

Android view.request focus

Despite,
i use xml codes:
android:focusable="true"
android:focusableInTouchMode="true"
Or clear and request focus:
CountEdit1.clearFocus();
CountEdit1.requestFocus();
Or in java set focusable:
view.setFocusableInTouchMode(true);
view.requestFocus();
Or use input manager:
InputMethodManager iMM = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
etv1.requestFocus()
iMM.showSoftInput(etv1, InputMethodManager.SHOW_IMPLICIT);
i didn't get any solution for show input window again(it just Works for first onclick). These are relative code snippet:
imagearama.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("tago", "onclicktıklandı");
InputMethodManager iMM = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
etv1.requestFocus();
iMM.showSoftInput(etv1, InputMethodManager.SHOW_IMPLICIT);
editTextAyarla(etv1, imagesimge, logo, imagearama);
}
});
These are backpressed codes :
View view = getCurrentFocus();
InputMethodManager iMM = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
iMM.hideSoftInputFromWindow(view.getWindowToken(), 0);
view.clearFocus();
I want that when user clicks "imagearama" button , input window be opened.(It just occurs first click)
Relative xml code snippet :
<EditText
android:id="#+id/aramaalani"
android:layout_width="250dp"
android:layout_height="50dp"
android:textColor="#33ff33"
android:background="#843221"
android:focusableInTouchMode="true"
android:hint="Aramak istedigini gir"
android:singleLine="true"
/>

Make android keyboard auto popup in dialog

I have a dialogue which prompts a user to enter in a 4 digit pin.
I would like for the keyboard to automatically be displayed when this dialog fragment popup is shown,
I have tried the following but I have not come right
<EditText
android:id="#+id/entercode_dialog_editText_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:inputType="numberPassword" >
<requestFocus />
</EditText>
Try This for Showing KeyBoard:
InputMethodManager imm = (InputMethodManager)getactivity().
getSystemService(Context.INPUT_METHOD_SERVICE);
solutiuon1:
if(imm != null){
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
solution2:
if(imm != null){
imm.showSoftInput(ed, 0);
}
where ed is your edittext
one more solution (not tried yet)
after inializing dialog
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Use this:-
myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
To appear the soft keyboard , you can use
EditText yourEditText= (EditText) findViewById(R.id.et);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
To close it you can use
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
Hope Can Help You

EditText onClick not shows Virtual Keyboard

If i click on my EditText, the virtual keyboard simple not shows up. The cursor is shown, but no keyboard to type on.
I even tried it with manually open but just no works.
Here is my code:
public class CreateNote extends Activity {
EditText titleEdit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.createnote);
titleEdit = (EditText) findViewById(R.id.titleEdit);
titleEdit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) CreateNote.this
.getSystemService(Service.INPUT_METHOD_SERVICE);
imm.showSoftInput(titleEdit, 0);
}
});
}
}
Snippet of Layout:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#989898" >
<EditText
android:id="#+id/titleEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittextdrawale"
android:ems="10"
android:textColor="#fff"
android:textColorHint="#fff" >
<requestFocus />
</EditText>
</FrameLayout>
What could be the reason of playing hide and seek of my virtual keyboard ?
I test on real device, not on emulator.
Try with this, it worked for me.
EditText etHorseName = (EditText) getView().findViewById(R.id.horseName);
etHorseName.clearFocus();
in onCreate() or where you want.
Late answer but here is how to solve it without adding code, just remove this from your XML:
<requestFocus />
No idea why the keyboard does not show up when this is set... It does show up however if you first loose the focus and then click on the edit text. I had the problem on Android 2.3.6 but it worked on 4.1.2, so maybe it was an early bug.
It is just a default behavior , you not suppose to do it manually, remove below part from your code.
titleEdit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) CreateNote.this
.getSystemService(Service.INPUT_METHOD_SERVICE);
imm.showSoftInput(titleEdit, 0);
}
});
Try to hide and show the keyboard with this code:
InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
// To show keyboard
imm.showSoftInput(titleEdit, 0);
// To hide keyboard
imm.hideSoftInputFromWindow(titleEdit.getWindowToken(), 0);

Android: hide keyboard when touch inside a customized Dialog

I have a customized Dialog. Inside the dialog, there's an EditText. When I touch inside the EditText, the soft keyboard is shown. I want to hide this keyboard when I touch inside the other place of the Dialog.
I know how to hide a keyboard in activity. I just don't know how to do this in Dialog.
Thank you.
You can do that easy by using focuslisners, see my code sample below:
EditText.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT);
}
else
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(EditText.getWindowToken(), 0);
}
}
});
edit:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable = "true"
android:isFocusableInTouchMode = "true"
android:clickable = "true" >
<EditText
android:id="#+id/EditText"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:hint="hint"
android:singleLine="true" />
</LinearLayout>
</RelativeLayout>
\to be sure to get focus:
LinearLayout actionHide = (LinearLayout) findViewById(R.id.wrapper);
actionHide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
actionHide.requestFocus(); // use this to trigger the focus listner
//or use code below to set the keyboard to hidden
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(EditText.getWindowToken(), 0);
}
});
Try by setting InputMethodManager.SHOW_FORCED for Edittext :
InputMethodManager input_manager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
input_manager.showSoftInput(edittext, InputMethodManager.SHOW_FORCED);

Categories

Resources