I have started using TextInputLayout. I want the hint of the EditText to align in the center. But for for some reason the hint isn't getting aligned to the center. However, once I start typing in the EditText field, the text is tetting aligned to the centre. Please help me with the proper alignment. I want my hint to be center aligned as well.
<android.support.design.widget.TextInputLayout
android:id="#+id/dobLyt"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/dob"
style="#style/MyEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:hint="Date of Birth"
android:inputType="number"
android:textColor="#333333"
android:textSize="15dp" />
</android.support.design.widget.TextInputLayout>
use this
<EditText
android:id="#+id/et"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:gravity="center_vertical|center_horizontal"
android:inputType="numberDecimal"/>
Related
I want to align the drawable and hint at center in EditText. For that I am having this piece of code,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/relative_layout"
android:layout_margin="5dp" >
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Hint"
android:background="#null"
android:gravity="center"
android:textColor="#android:color/black"
android:textColorHint="#color/black"
android:textSize="14sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:drawableLeft="#android:drawable/icon"
android:drawableStart="#android:drawable/icon" />
</RelativeLayout>
Now as soon as user starts typing, the drawable should move to extreme left of EditText. How to achieve this?
Use android:layout_gravity="center" for your EditText. This will help you setting hint in center.
and for drawable this is hack. Set your drawableTop for editText and give some paddingTop to the view.
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 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"
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
How show hint message in Hebrew language?.If I remove "android:inputType="phone""
message show.
I have tried "android:ellipsize="start"", add some unicode but not work.
Is any way to show hint in Hebrew with "android:inputType="phone""?
Code:
<EditText
android:id="#+id/mobile"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1"
android:background="#drawable/drawrect_layout"
android:hint="#string/mobile"
android:inputType="phone"
android:padding="6dp"
android:textColor="#000000"
android:textSize="15sp" />
I think you are setting width to 0dp that is why you are getting this problem. Please use wrap_content or fill_parent. I have edited this and is working at my side.
<EditText
android:id="#+id/mobile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="mobile"
android:inputType="phone"
android:padding="6dp"
android:textColor="#000000"
android:textSize="15sp"
android:layout_below="#id/text" />