disable popout keyboard android-studio - android

I have an EdiText in my project developed on android studio .
android:id="#+id/Number"
android:layout_width="match_parent"
android:layout_height="100dp"
android:textSize="24dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
I need to find a way to disable the keyboard when I click on the edit text, meaning that when I click on the EditText the keyboard should not open .

Just disable it.
EditText et = (EditText) findViewById(R.id.edittext);
et.setEnabled(false);
OR
Add android:inputType="none" in your xml

Do it this way
final EditText editText = findViewById(R.id.Number);
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});

here you go.
public static void disableSoftInputFromAppearing(EditText editText) {
if (Build.VERSION.SDK_INT >= 11) {
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
} else {
editText.setRawInputType(InputType.TYPE_NULL);
editText.setFocusable(true);
}
}

In your code you need to do it programmatically this way: declare a global variable for InputMethodManager:
private InputMethodManager im ;
In onCreate() method define it:
im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(youredittext.getWindowToken(), 0);
Set the onClickListener to that edit text inside onCreate():
youredittext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
im.showSoftInput(youredittext, InputMethodManager.SHOW_IMPLICIT);
}
});
This will work.

If you want to prevent user to edit text then you may use android:enabled="false" property in edittext

Related

EditText Android| input text by pressing a button

How to implement the method, when the button is clicked, EditText can be edited. Before this, EditText must be closed for text entry.
code located below does not help
Entertext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Total.setFocusable(true);
}
});
Try this use android:focusable="false" in xml to disable your EditText
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
now enabled your Edittext inside button click listener using android:focusable like this
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true);
edittext.setEnabled(true);
edittext.requestFocus();
}
});
make edittext in xml as focusable false like below ..
android:focusable="false"
then after click event used below code..
Entertext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Total.setFocusable(true);
Total.setFocusableInTouchMode(true);
Total.requestFocus();
}
});
you can also used enable and disable concept in edittext.

Textview onclick open keyboard and set the input as Textview's text

I am trying to click on textview and open keyboard (i did that) and then what the user inputs i want to set that text in particular text view. I am using Fragments.
Getting keyboard by:
TextView test = (TextView) rootView.findViewById(R.id.txtSent);
test.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}// end onClick
});
set android:editable="true". Although you're better off with an EditText.

How to go to Edittext when button clicked in android

I have a layout which contains button at top and some textviews and then at bottom I have edittext.When I click button, it should point to edittext. How to proceed? Thanks in advance.
To show keyboard when EditText is in focus mode.
myEditText.requestFocus();
if(myEditText.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
If you want to show some message
myEditText.setError("Please Enter Valid Value!");
You can remove message focus by Using:
myEditText.clearFocus();
In onClick method of a button write this edittext.requestFocus();
onButtonClick write below code
myedittext.requestFocus();
Try this,
OnClickListener buttonListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText edit = (EditText)v.findViewById(your edittxt id);
edit.requestFocus();
}
}
Yes go with requestFocus().
Inside your onClick() method write,
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editText.requestFocus();
}
private fun getKeaboardButtonListener(view: LinearLayout): View.OnClickListener {
return View.OnClickListener {
val editText :EditText = view.findViewById(R.id.editText)
editText.requestFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
}

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);
}
});

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>

Categories

Resources