soft Keyboard isn't shown when EditText is set invisible android - android

I am doing Project of Remote Administration
I am getting screen of Remote PC on mobile screen but to send keyboard events I need an invisible edittext and a button which enable and disable keyboard
if i remove edittext invisibility it works but edittext is shown on screen i don't wannt that
here is code
<EditText
android:id="#+id/KeyBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:focusable="true"
android:inputType="textVisiblePassword"
android:text=""
android:visibility="invisible" >
</EditText>
Show and hide Keyboard by setting the focus on a hidden text field
public void keyClickHandler(View v) {
EditText editText = (EditText) findViewById(R.id.KeyBoard);
editText.requestFocus();
InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (keyboard) {
inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
keyboard = false;
} else {
inputMgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
keyboard = true;
}
Log.d("SET", "Foucs");
}
This method is called on button click
If I remove android:visibility="invisible" from edittext then it works

You mean to hide it all?
you can use:
editText.setVisibility(View.GONE);
or
editText.setVisibility(View.INVISIBLE);
EDIT
Try this one:
editText.setBackgroundColor(color.transparent);

Another easy way to 'hide' your EditText would be to just make its Height/width to 0dp, as below, so that it is not visible to the users.
android:layout_width="match_parent"
android:layout_height="0dp"

Related

How to show keyboard only when user click on edit text box to insert text? [duplicate]

This question already has answers here:
How to hide Soft Keyboard when activity starts
(23 answers)
Closed 4 years ago.
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:drawableLeft="#drawable/search"
android:background="#drawable/search_bar"
android:paddingLeft="15dp"
android:drawablePadding="10dp"
android:inputType="text"
android:id="#+id/srchbar"
android:onClick="searchBarClick">
</EditText>
public void searchBarClick(View view){
}
I have an edit text box and onClick function.Please tell how to show keyboard ONLY when user click on edittext box to insert data.In normal condition,keyboard appears as i run my application but i only want it to be shown when user click on edittext box.
add this below code in the root element of your layout.
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
editText.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
}, 50);
sometime edittext might get focus after manually hide soft-keyboard.
so, delay some time and then after hide it forcefully in onResume() method of your activity or fragment

EditText on Huauei; unable to insert number with two or more digits

I'm facing a strange problem with my code. This is my layout:
<RelativeLayout
android:id="#+id/container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:digits="0123456789,."
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:textSize="#dimen/sp15" />
</RelativeLayout>
And this is code for opening keyboard:
container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(editText.hasFocus()) {
editText.clearFocus();
}
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(currentStake, InputMethodManager.SHOW_IMPLICIT);
}
});
Now on most devices, when i tap on container, text inside edittext is all selected, numeric keyboard appear and i can type numbers (for example 15,20, etc).
On Huawei devices the behavior is different. In fact when user tap on container text inside edittext is all selected, numeric keyboard appear, but every time i type a digit, text continue keep selected, so i'm not able to type numbers > 9.
For example if i type 20, when i press 2, on edittext 2 appear (but selected), and when i press 0, this replace 2 so i have a 0 inside edittext and not 20.
I'm going crazy to find a solution, how can i do?

Showing soft keyboard when click on grid view cell

I have a grid view and want to show a keyboard when the user clicks on a cell. The input of the keyboard will then appear in the cell. I've tried the code below which I got from Android: show soft keyboard automatically when focus is on an EditText and other similar questions. I can't get the keyboard to show up, though.
Any ideas on this?
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(gridView, InputMethodManager.SHOW_IMPLICIT);
}
});
I have tried InputMethodManager.SHOW_FORCED but that didn't help either.
Thanks
EDIT
The cell layout for the grid is below. I changed it to an EditText but still no keyboard. Having it as EditText doesn't look too good for me from a UI point of view. Ideally, I was the TextView and then perhaps when the user clicks it becomes an EditText so the user can enter something.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<EditText
android:id="#+id/grid_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/celllabel"
android:textSize="15px" >
</EditText>
My idea is that it stays as a TextView. The keyboard opens and when the user clicks one letter the keyboard closes and that a letter appears in the GridCell. Is my idea possible?
Thanks
One suggestion:
Create a custom EditText, you can hide the cursor if you want (make it looks like a TextView).
Optimize your cell layout by removing the LinearLayout
Code:
<?xml version="1.0" encoding="utf-8"?>
<YourCustomEditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid_item_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#+id/celllabel"
android:maxLength="1"
android:textSize="15px" >
</YourCustomEditText>
Use TextWatcher or focus interface to control the show/hide of the keyboard.
Hope this help!

Showing and hiding the soft keboard does not work

Not sure if it's relevant but I'm using LG G3 with Android 4.4.2
I have a fragment where I want the keyboard to show, so I did the following:
txtContact = (EditText) rootView.findViewById(R.id.txtContact);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtContact.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
and the layout is this, including requestFocus for the relevant field:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:lines="10"
android:layout_margin="10dp"
android:id="#+id/txtContact">
<requestFocus />
</EditText>
When opening this fragment, the cursor is where it should be but the keyboard is not there, Only when tapping inside the field, they appear.
The other problem is the opposite of the first one. On another fragment, I want to hide the keyboard when the fragment opens, no matter what. The reason for this, is that the user can open this fragment after closing a different one, where the keyboard was shown so I want to make sure it closes, notice that I don't know if the keyboard is shown, I want it to remain close if it was or to be closed if it was open. I only have a ListView in this fragment, so I did the following:
lv = (ListView) rootView.findViewById(android.R.id.list);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(lv.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
but it refuses to make any effect on the keyboard and it remains open.
What am I doing wrong?
Try to call the code in onResume() or post() it as a Runnable.
If your Fragment is a DialogFragment, calling getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); in onCreateView() should be sufficient.

EditText box cursor appear after touching box?

I am using EditText in my app. I want that the cursor appears only after user touches the edit text box. how could I do this?
I have used this to hide the cursor first.
EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:cursorVisible="false"
android:ems="10"
how could I show it after touch?
Try to request focus for other views instead of letting your edittext get the focus in the first time view loaded. <requestFocus /> put this to your main view.
Try : edittext.clearFocus(); you can put it in the onCreate() it will set focus to the first view.
Implement :
mText = (EditText) findViewById(R.id.editText1);
OnTouchListener otl = new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
mText.requestFocus()
return true;
}
};
mText.setOnTouchListener(otl);
Go to Layout file of your project and remove <requestFocus /> from the EditTexts for which you want the cursor to appear only when the user taps on the EditText box.
If in your layout file
<requestFocus />
is there, then just remove from the Edittext and because of this the cusrsor is only visible when user tap on to Edittext.

Categories

Resources