Implicit Intent for show keyboard - android

I need to know how show a keyboard without show the TextView, and I had thought of using Implicit Intents, but I dont see any example.
I currently I have this code:
For layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".LoginActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="#+id/keyboardPassword"
android:inputType="numberPassword|textPassword"
android:visibility="visible"
android:maxLength="4"
android:textColor="#android:color/transparent"
android:selectAllOnFocus="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/userListing"
android:layout_weight="1"
android:touchscreenBlocksFocus="true"
android:longClickable="true"
android:fastScrollEnabled="true"
android:clickable="true"
android:smoothScrollbar="true"
android:divider="#android:color/black"
android:dividerHeight="1.0sp"
android:scrollingCache="true"
android:layout_centerHorizontal="true"
android:layout_above="#+id/keyboardPassword" />
</RelativeLayout>
For class:
private void showKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
});
}
private void registerKeyboardClickCallback() {
final TextView keyboard = (EditText) findViewById(R.id.keyboardPassword);
keyboard.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
//action
}
return false;
}
});
}
With this code the line of TextView appears, and if I hide the textView, the Keyboard never show
Thanks! Greetings!

Related

Add layout at bottom with edit text on it and hide it if the edit text is not focused

How to add layout at bottom with edit text on it when pressed button "plus" and hide the layout if the edit text is not focused
please look at this picture example
Add OnFocusChangeListener to the EditText and inside the Overrided onFocusChange(View v, boolean hasFocus) method add or remove your layout based on hasFocus value (its true if it has focus).
Refer this for more on OnFocusChangeListener
Your layout must have a ListView, an EditText, and a FloatingActionButton. Place all these within a RelativeLayout. An example of this would be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="abcd.MainActivity">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:id="#+id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input"
android:id="#+id/input"
/>
</android.support.design.widget.TextInputLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_above="#id/fab"
android:divider="#android:color/transparent"
android:id="#+id/list"/>
</RelativeLayout>
The back button by default does the function of closing the TextInputLayout. To close it on touching it outside, you can add the following to your activity.
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if ( v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
v.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return super.dispatchTouchEvent( event );
}

Soft keyboard not open in android [duplicate]

This question already has answers here:
Android: softkeyboard not showing up
(5 answers)
Closed 6 years ago.
I am newbie to android and working on a demo app,In that i am having an activity contains an edittext at the top of the screen and want to show the keyboard on the start of that activity i have tried many ways but none of this works,Can anybudy help me to sort it ot?
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rl_hdr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#16BBA1"
android:gravity="center_vertical"
android:padding="10dp">
<ImageView
android:id="#+id/iv_back"
android:layout_width="25dp"
android:layout_height="22dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:src="#drawable/ic_back_white" />
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textColorHint="#939393"
android:singleLine="true"
android:layout_centerInParent="true"
android:hint="Search"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:gravity="center_vertical"
android:drawablePadding="5dp"
android:layout_marginRight="5dp"
android:textSize="16dp"
android:imeOptions="actionDone"
android:cursorVisible="true"
android:layout_toRightOf="#+id/iv_back"
android:drawableRight="#drawable/ic_search"
android:background="#drawable/bg_et_actionbar"
android:id="#+id/et_search" />
</RelativeLayout>
<FrameLayout
android:id="#+id/fragmentTimeline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp" />
</LinearLayout>
manifest.xml
<activity
android:name="one.tusk.stush.SearchPostActivity"
android:label="Back"
android:parentActivityName="one.tusk.stush.activities.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible" >
>
</activity>
SerachPostActivity.java
public class SearchPostActivity extends FragmentActivity implements OnQueryTextListener, OnItemClickListener {
public EditText et_search;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search_post);
.
.
.
.
et_search = (EditText)findViewById(R.id.et_search);
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i("Done pressed", "Enter pressed");
search.searchPost(et_search.getText().toString().trim());
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return false;
}
});
et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_search, InputMethodManager.SHOW_FORCED);
} else {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
});
You have to give focus to EditText.Try
android:focusable="true"
in your EditText and it will open the soft keyboard.
Try changing your manifest to
android:windowSoftInputMode="stateVisible"
instead of
android:windowSoftInputMode="stateAlwaysVisible".
If problem persists,try opening it programatically using
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, 0);
You may also refer This answer on SO

Move to next Edit text

i have customEditText
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/five_margin"
android:focusableInTouchMode="true"
android:orientation="horizontal"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout"
>
<EditText
android:id="#+id/edt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="#dimen/sub_heading"
android:textColorHint="#color/hind_text_col0r"
android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
android:textColor="#color/active_text_col0r"
/>
</android.support.design.widget.TextInputLayout>
and using it As follow
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.paisa.main.base.ui.widget.CustomEditText
android:id="#+id/custom_edt_investor_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
/>
<com.paisa.main.base.ui.widget.CustomEditText
android:id="#+id/custom_edt_nominee_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
how can i move investor name to nominee name edit text via soft input keyboard
i had use imeoption next bt it didn't work its hide the keyboard.
This will helps you :- make this for all TextView ...
custom_edt_investor_name.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
custom_edt_investor_name.clearFocus();
custom_edt_nominee_name.requestFocus();
return true;
}
return false;
}
});
Use the android:nextFocusDown param to specify which field you'd like to get focus when the user hits the enter key.
Example :
android:inputType="text"
android:nextFocusDown="#+id/..."

scrollView.requestFocus() returns true, but it not works

All,I hava a scroll contains a editText.
Once I clicks the editText ,it gets focus and a SoftInput shows.
In my mind, if I clicks the blank space , the softinput hide, and editText lose the focus, and scrollview get focus.
So my code like this:
scrollView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
//call twice, once down, once up
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null) {
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
scrollView.requestFocus();
activity.getCurrentFocus();
}
}
return false;
}
});
ScrollView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/scrollView"
android:layout_below="#+id/topBar"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
But after all, editText still focus(activity.getCurrentFocus() == editText), any advices?
Use LinearLayout instead of ScrollView. Or wrap EditText with LinearLayout below.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout"
android:layout_gravity="center_horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText" />
</LinearLayout>
</ScrollView>

How to make button come down after edit text field?

I have a piece of code which shows a static text, an edit text as a search box and a submit button to submit the query .
The code kind of looks like this :
public class MyActivity extends Activity {
TextView textView;
private EditText edittext;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mine);
textView = (TextView) findViewById(R.id.textView1);
textView.setText("Enter your search String :");
addKeyListener();
addListenerOnButton();
}
//Implement the method
public void addKeyListener() {
// get edit text component
edittext = (EditText) findViewById(R.id.searchText);
// add a key listener to keep track user input
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// if key down and "enter" is pressed
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// display a floating message
Toast.makeText(RecipeActivity.this,
edittext.getText(), Toast.LENGTH_LONG).show();
return true;
} else if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_9)) {
// display a floating message
Toast.makeText(RecipeActivity.this,
"Aboriginal text!", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
}
//Implement the button
public void addListenerOnButton() {
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
/* I will capture the search string here */
}
});
}
}
The activity screen comes up like this :
EDIT : The XML layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".RecipeActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:label="#string/search_label"
android:hint="#string/search_hint" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</RelativeLayout>
As you can see the submit button is overlapping the edit text search box. How can i make the button element come down ?
It would be better to use LinearLayout with android:orientation="vertical" in your xml Layout because it's much cheaper than RelativeLayout to render.
Solution with LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
If you have to use RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/searchText"
android:text="Submit" />
</RelativeLayout>
See RelativeLayout Documentation for further Informations.
Use android:layout_alignParentBottom="true" in your
add android:below reference
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:below="#+id/searchText"
android:text="Submit" />

Categories

Resources