I have search bar that defines EditBox like
<EditText
android:id="#+id/search_editbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/search_execute_imageview"
android:layout_toRightOf="#id/layout_back_logo"
android:gravity="left"
android:hint="#string/search_hint"
android:maxLength="20"
android:textCursorDrawable="#null"
android:drawableRight="#drawable/abc_ic_clear_holo_light"
android:background="#drawable/rounded_edittext_states"
android:padding="5dip"
android:singleLine="true"
android:textSize="#dimen/main_text_size" />
Despite android:layout_centerVertical="true" the text is not in the middle, but closer to upper side.
Use
android:gravity="left|center_vertical"
The correct answer is right but it is recommended to use:
android:gravity="start|center_vertical" instead of ("left") to avoid formatting errors.
try this:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:ems="10"
android:gravity="left|center_horizontal"
android:textAlignment="center" >
</EditText>
just change your gravity value to "left center align".
android:gravity:"left|center"
Related
I am creating an android application in which i am collecting user's some messages.But i am getting some issues such as following..
I have added 3 edit text in alert dialog..the third edit text box having multi line textbox so whenever i am adding multiple lines its getting overlapped to above two edit text
here is the snapshot of the error
Here Is Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ScrollView
android:layout_width="245dp"
android:layout_height="245dp"
android:layout_weight="0.40"
android:layout_gravity="center_horizontal">
<RelativeLayout
android:layout_width="245dp"
android:layout_height="200dp">
<EditText
android:layout_width="235dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText6"
android:layout_gravity="center_horizontal"
android:hint="Your Email Id"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:id="#+id/editText4"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:singleLine="true"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /></RelativeLayout></ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/button10"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Reason for your issue is android:inputType="textMultiLine" pushes content when there is a new line!
You can use android:maxLines="1" for your EditText [any way this will be useful for you since you have used android:singleLine="true" with is kind of dipricated ]
Ps: Hard coding android:maxLength will not solve your issue since screens can be in different sizes which makes you hard to decide how many lines you keep!
Also you can use android:maxHeight="xdp" for the editText view, then the limit won't exeed!
You should use
android:maxLength="4"
row numbers you want to fix for your edit text
Use LinearLayout with vertical orientation instead of RelativeLayout.
If u want to use RelativeLayout, then set layout_below attribute of RelativeLayout.
You need to set android:maxLines="4". Set your max lines to solve this issue.
<EditText
android:id="#+id/editText4"
android:maxLines="4"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:layout_alignParentStart="true" />
You can use android:layout_below and android:layout_marginTop in your EditText views and keep distance between your views.
Example :
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText4"
android:layout_marginTop="20dp"/>
I have a normal edittext like this :
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:background="#android:color/transparent"/>
How can I make the cursor stay always in the center of edittext? No matter if user enters something or not. Thanks.
Try adding the following code
android:gravity="center"
This makes sure that your text will always be entered in the center of the EditText. By default its value is left.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:gravity="center"
android:background="#android:color/transparent"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:hint="Some hint text"
></EditText>
please Try adding the following code
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:id="#+id/et_word"
android:ems="12"
android:background="#android:color/transparent"/>
Here you can add to property in xml file to gravity center then you can get cursor center
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/et_word"
android:ems="12"
android:gravity="center"
android:background="#android:color/transparent"/>
That can be write from center also.
I've a EditText and a AutoCompleteTextView and the text starts not on the same position which looks a bit strange.
I'm using appcompat v7 and I don't know if it's possible to fix this.
The line in the bottom is also different (so so bad as the text begin)
I also tried to style it like appcompat's EditText, but that doesn't look like that.
Code
<EditText
android:id="#+id/input_ipAdresse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignEnd="#+id/button_berechnen"
android:layout_alignRight="#+id/button_berechnen"
android:ellipsize="end"
android:gravity="start"
android:hint="#string/input_ipAdresse"
android:imeOptions="flagNoExtractUi"
android:inputType="phone"
android:paddingStart="#dimen/padding_small"
android:paddingEnd="#dimen/padding_small"
android:textSize="#dimen/fontsize_medium" >
<requestFocus android:layout_width="match_parent" />
</EditText>
<AutoCompleteTextView
android:id="#+id/input_snm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_below="#+id/input_ipAdresse"
android:ellipsize="end"
android:gravity="start"
android:imeActionLabel="#string/Button_berechnen"
android:imeOptions="actionDone|flagNoExtractUi"
android:inputType="phone"
android:paddingStart="#dimen/padding_small"
android:paddingEnd="#dimen/padding_small"
android:textSize="#dimen/fontsize_medium" />
i've an edittext :
<EditText android:id="#+id/chp"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:layout_height="340dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="top"
android:hint="#string/hintCommentaire"
android:textSize="25sp"
android:drawablePadding="10dp"
android:drawableLeft="#drawable/ic_comment"
android:layout_margin="5dp" />
The problem is, i've my hint at the top of the edittext, but the drawable stays in the center..
I tried with "drawableStart", but it's not working.
Someone to help me ?
EDIT : I want the text and drawable in the top(same line). (i want to keep the height of my edittext)
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/etMobile"
android:hint="Mobile"
android:fontFamily="sans-serif-normal"
android:singleLine="true"
android:textSize="15sp"
android:gravity="center|start"
android:textCursorDrawable="#null"
android:drawableStart="#drawable/ic_profile_bio"
android:drawablePadding="10dp"
app:met_floatingLabel="normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
Set this Property android:gravity="center|start" in above EditText
I want to make the multiline text auto scroll down as I add in more text:
<EditText
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/TypeBox"
android:layout_below="#+id/ReceiverName"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="0.65"
android:ems="10"
android:focusable="false"
android:gravity="bottom"
android:inputType="textMultiLine|textNoSuggestions" >
</EditText>
I have tried searching for it but all i could find is auto scroll of a text box within a scroll view.
android:inputType="textMultiLine"
android:editable="true"
android:enabled="true"
android:minLines="6"
android:maxLines="6"
android:isScrollContainer="true"
android:focusable="true"
Refer this link for more info
https://alvinalexander.com/source-code/android/android-edittext-isscrollcontainer-example-how-make-multiline-scrolling
I think, you need to add a line:
android:inputType="textFilter|textMultiLine|textNoSuggestions"
Add bellow code in activity onCreate(), this Add scroll behavior to
text view
textView.setMovementMbehavior ScrollingMovementMethod());
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="text"
android:textColor="#ffffff"
android:textSize="20sp"/>