EditText Scrollable with keyborad active - android

Well friend ..
I have a design so:
The main Scroll is very necessary when appear the keyboard... If i dont make that, the button can't see...
The problem is when i try move inside the Edittext with the keyboard active...
I tried this:
android:scrollbars="vertical"
and this:
setMovementMethod(new ScrollingMovementMethod());
but not solve this yet
Anyone help me?
grax advance!

Check this without using scroll bar:
add permission in menifest file for corresponding activity.
android:windowSoftInputMode="adjustPan"

Please try this:
Your layout should be similar to example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext"
android:layout_width="200dp"
android:layout_height="500dp"
android:text="some long text"
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
and in your java try this:
EditText edit = (EditText)findViewById(R.id.edittext);
edit.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.edittext) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
It could be helpful.

Related

how to detect tap anywhere on listview

I want an action to be performed every time I click on the screen . There is a list view inside Relative layout. When i set setOnCLickListener for relative layout alone when there is no listview inside it it is working but not with listview inside it. The items in the listview will be displayed only when I click on the screen each time . I tried setItemOnClickListener.Thats not working too.
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"
android:clickable="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:background="#drawable/bg">
<ListView
android:id="#+id/list_msg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_below="#+id/meLbl"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:listSelector="#android:color/black"
android:transcriptMode="alwaysScroll"
android:divider="#null" />
<TextView
android:id="#+id/meLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="Amanda"
android:textColor="#color/white"
android:textSize="20dp" />
<TextView
android:id="#+id/friendLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Janet"
android:textColor="#color/white"
android:textSize="20dp" />
</RelativeLayout>
The click is working only on the two text views not on the screen.
I want the click to work on the screen
for find out clicked on screen :
getWindow().getDecorView().setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View arg0, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Toast.makeText(SecondActivity.this, "click on screen ", Toast.LENGTH_SHORT).show();
}
return false;
}
});
and for find out clicked on listView :
listView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(SecondActivity.this, "Clicked On ListView", Toast.LENGTH_LONG).show();
return false;
}
});

Android EditText with icon/button

How can I obtain an EditText as those bellow?
The x button removes the text inserted and the eye button displays the clear password as long as it's pressed. Note that I refer to them as buttons because I don't really know what they actually are nor if they are part of the EditText itself or if they are independent views.
You can just add a button at the right of your EditText
<FrameLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/ScreenLoginContainer">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:hint="#string/enter_password_hint"
android:paddingRight="30dp"
style="#style/ScreenPasswordEditText"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+screen_card_ean_enter/show_password_button"
style="#style/ShowHidePasswordButton"/>
</FrameLayout>
You can use android:drawableRight
Set a Drawable to the right of the text, in EditText, in XML .
android:drawableRight="#drawable/Your_drawable"
You can use this :
android:drawableRight="#drawable/your_icon"
Also for click this answer
may help
This is the prefect way to create an EditText with cross button at the end:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:padding="5dp">
<EditText
android:id="#+id/calc_txt_Prise"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:layout_marginTop="20dp"
android:textSize="25dp"
android:textColor="#color/gray"
android:textStyle="bold"
android:hint="#string/calc_txt_Prise"
android:singleLine="true" />
<Button
android:id="#+id/calc_clear_txt_Prise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="right|center_vertical"
android:background="#drawable/delete" />
And now to clear the EditText upon click you can use
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditTextID.setText("");
}
});
And in order to make the password visible till the button is pressed, you can implement it this way:
yourButton.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch ( event.getAction() ) {
case MotionEvent.ACTION_DOWN:
editText.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case MotionEvent.ACTION_UP:
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
break;
}
return true;
}
});
The design support library has a setPasswordVisibilityToggleEnabled method: https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setPasswordVisibilityToggleEnabled(boolean)
This would be good for your password edittext, but not the username one.

Start outSide scroll after edittext scroll finished

I've tried every simple examples on stackoverflow but nothing can solve my problem. Here's my question
I have ScrollView in activity and I have scrollbars="vertical" option editText inside ScrollView.
I want to scroll outside scrollview's scroll after inside edittext scroll finish, like on top of the edittext scroll or bottom of the edittext scroll
I thought that it can be done with view catchs scroll lisetener but nothing worked.
Try the below sample code hope it works for you.
In XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa8822"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aa8822"
android:orientation="vertical" >
<EditText
android:id="#+id/edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:ems="10"
android:maxLines="3"
android:scrollbars="vertical"
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold" >
<requestFocus />
</EditText>
</LinearLayout>
</ScrollView>
Put some more view so the scroll view scroll works.
Now in your activity-
EditText edt = (EditText) findViewById(R.id.edt);
edt.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.edt) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});

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>

ScrollBar doesnt work in EditText

Hope all of you doing well.
My Problem is:
I have xml code like following:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_left_margin"
android:layout_marginRight="#dimen/activity_right_margin"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_bottom_padding"
android:paddingTop="#dimen/activity_top_padding" >
<EditText
android:id="#+id/custDetailsNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name_cust_all_add"
android:inputType="textPersonName"
android:textSize="#dimen/common_fontsize" />
<EditText
android:id="#+id/custDetailsDescEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="#string/description_add_all_cust"
android:inputType="textMultiLine"
android:lines="5"
android:minLines="3"
android:gravity="top|left"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:overScrollMode="always"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:textSize="#dimen/common_fontsize" />
</LinearLayout>
</ScrollView>
In that i have two EditText in </ScrollView>, Second <EditText/> does not scrolling inner side. Problem is Full View is scrolled while i am scrolling but i want to also scroll vertically in second EditText when user enter more than 5 lines. In that ScrollBar is displaying but not scrolling.
How can i solve this.
Your Help would be appreciated.
This code should work.....
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.parentScrollView).setOnTouchListener(parentListener);
findViewById(R.id.custDetailsDescEditText).setOnTouchListener(childListener);
}
OnTouchListener parentListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.custDetailsDescEditText).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
};
OnTouchListener childListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
};
Try something like this in your code
ScrollView scroller = new ScrollView(this);
EditText et=(EditText)findViewById(R.id.yourEdittext);
scroller.addView(et);

Categories

Resources