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"
/>
Related
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);
}
I want to make similar feature in my app imageview onClick open keyboard that i have done and keyboard is opening very well.
I'm using a relative layout i have placed the image of keyboard on the edittext which is similar to this reference hangouts image.
problem is when i type something it does not show up in edittext's text field. How to handle it? guide me
protected void onCreate(Bundle savedInstanceState) {
imageview = (ImageView) findViewById(R.id.keyboard);
imageview.setFocusableInTouchMode(true);
imageview.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
try {
showSoftKeyboard(imageview);
} catch (Exception e) {
Log.e("Error MA onCreate keyboard open", "Error");
}
break;
}
return true;
}
});
}
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
this is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="12dp" >
<ImageView
android:id="#+id/keyboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="true"
android:src="#drawable/ic_action_keyboard" />
<EditText
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/keyboard"
android:hint="Search Here"
android:focusable="true" />
</RelativeLayout>
<ListView
/>
</RelativeLayout>
Problem: imageView is calling the softkeyboard.
Possible solution: After clicking on the imageView call showSoftKeyboard() method using your edittext as a parameter.
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
// myEditText.requestFocus();//this line is also worth a try
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
mEditText.setFocusable(true);
mEditText.requestFocus();// this line is also worth a try
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);//sending mEditText here in the parameter solved my problem instead of sending view
}
}
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
In my app after some event i want my user to fill EditText. In order to do that, i request focus on this EditText and try to show keyboard using this code:
public void onGivenEvent(int which) {
mMyDialog.dismiss(getActivity());
mMyEditField.requestFocus();
InputMethodManager imm =
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mMyEditField, InputMethodManager.SHOW_IMPLICIT);
}
xml for mMyEditField looks like this:
<EditText
android:id="#+id/edit_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:background="#null"
android:digits="0123456789.,"
android:freezesText="true"
android:hint="some hint"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLength="15"
android:selectAllOnFocus="true"
android:singleLine="true"
android:textColor="#android:color/black"
android:textSize="16sp" />
The funny thing is, this code doesn't show keyboard on first attempt. When this code is executed once, after device rotation keyboard is shown properly. I had similiar problem with android:selectAllOnFocus="true"not working correctly, but i used workaround - I set OnFocusChangeListener with mMyEditField.selectAll() inside.
Any ideas how to fix this issue?
Call This method from your onGivenEvent() function
public void showSoftKeyboard() {
try {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
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);